memory leaks removed

This commit is contained in:
h_vogt 2009-04-05 08:02:03 +00:00
parent ddbcc17fc9
commit e43430a669
8 changed files with 177 additions and 140 deletions

View File

@ -1,3 +1,8 @@
2009-04-05 Holger Vogt
* com_fft.c, inpcom.c, variable.c, variable.h, resource.c, cpitf.c,
plotit.c:
some more memory leaks removed
2009-04-01 Dietmar Warning
* frontend/resource.c, misc/misc_time.c: init of rusage structure to prevent
read of uninitialized memory, found with dbx under solaris

View File

@ -168,6 +168,7 @@ com_fft(wordlist *wl)
}
free_pnode_o(first_name); /* h_vogt 081206 */
if (!ngood) {
tfree(win);
return;
}
@ -239,7 +240,8 @@ com_fft(wordlist *wl)
tfree(imagd);
tfree(tdvec);
tfree(fdvec);
tfree(fdvec);
tfree(win);
}

View File

@ -272,6 +272,7 @@ cp_istrue(wordlist *wl)
cp_striplist(wl);
pn = ft_getpnames(wl, TRUE);
wl_free(wl);
v = ft_evaluate(pn);
/* It makes no sense to say while (all), but what the heck... */

View File

@ -1035,8 +1035,9 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name)
if ( call_depth == 0 && line_count == 0 ) {
line_count++;
if ( fgets( big_buff, 5000, fp ) ) {
buffer = tmalloc( strlen(big_buff) + 1 );
strcpy(buffer, big_buff);
/* buffer = tmalloc( strlen(big_buff) + 1 );
strcpy(buffer, big_buff); */
buffer = copy(big_buff);
}
}
else {
@ -2143,126 +2144,140 @@ inp_fix_subckt_multiplier( struct line *subckt_card,
static void
inp_fix_inst_calls_for_numparam(struct line *deck)
{
struct line *c = deck;
struct line *d, *p = NULL;
char *inst_line;
char *subckt_line;
char *subckt_name;
char *subckt_param_names[1000];
char *subckt_param_values[1000];
char *inst_param_names[1000];
char *inst_param_values[1000];
char name_w_space[1000];
int num_subckt_params = 0;
int num_inst_params = 0;
int i,j,k;
bool flag = FALSE;
bool found_subckt = FALSE;
bool found_param_match = FALSE;
struct line *c = deck;
struct line *d, *p = NULL;
char *inst_line;
char *subckt_line;
char *subckt_name;
char *subckt_param_names[1000];
char *subckt_param_values[1000];
char *inst_param_names[1000];
char *inst_param_values[1000];
char name_w_space[1000];
int num_subckt_params = 0;
int num_inst_params = 0;
int i,j,k;
bool flag = FALSE;
bool found_subckt = FALSE;
bool found_param_match = FALSE;
// first iterate through instances and find occurences where 'm' multiplier needs to be
// added to the subcircuit -- subsequent instances will then need this parameter as well
for ( c = deck; c != NULL; c = c->li_next ) {
inst_line = c->li_line;
// first iterate through instances and find occurences where 'm' multiplier needs to be
// added to the subcircuit -- subsequent instances will then need this parameter as well
for ( c = deck; c != NULL; c = c->li_next ) {
inst_line = c->li_line;
if ( *inst_line == '*' ) { continue; }
if ( ciprefix( "x", inst_line ) ) {
num_inst_params = inp_get_params( inst_line, inst_param_names, inst_param_values );
subckt_name = inp_get_subckt_name( inst_line );
if ( *inst_line == '*' ) { continue; }
if ( ciprefix( "x", inst_line ) ) {
num_inst_params = inp_get_params( inst_line, inst_param_names, inst_param_values );
subckt_name = inp_get_subckt_name( inst_line );
if ( found_mult_param( num_inst_params, inst_param_names ) ) {
flag = FALSE;
// iterate through the deck to find the subckt (last one defined wins)
d = deck;
while ( d != NULL ) {
subckt_line = d->li_line;
if ( ciprefix( ".subckt", subckt_line ) ) {
for ( ; *subckt_line && !isspace(*subckt_line); subckt_line++ );
while ( isspace(*subckt_line) ) subckt_line++;
if ( found_mult_param( num_inst_params, inst_param_names ) ) {
flag = FALSE;
// iterate through the deck to find the subckt (last one defined wins)
d = deck;
while ( d != NULL ) {
subckt_line = d->li_line;
if ( ciprefix( ".subckt", subckt_line ) ) {
for ( ; *subckt_line && !isspace(*subckt_line); subckt_line++ );
while ( isspace(*subckt_line) ) subckt_line++;
sprintf( name_w_space, "%s ", subckt_name );
if ( strncmp( subckt_line, name_w_space, strlen(name_w_space) ) == 0 ) {
p = d;
flag = TRUE;
}
}
d = d->li_next;
}
if ( flag ) {
num_subckt_params = inp_get_params( p->li_line, subckt_param_names, subckt_param_values );
sprintf( name_w_space, "%s ", subckt_name );
if ( strncmp( subckt_line, name_w_space, strlen(name_w_space) ) == 0 ) {
p = d;
flag = TRUE;
}
}
d = d->li_next;
}
if ( flag ) {
num_subckt_params = inp_get_params( p->li_line, subckt_param_names, subckt_param_values );
if ( num_subckt_params == 0 || !found_mult_param( num_subckt_params, subckt_param_names ) ) {
inp_fix_subckt_multiplier( p, num_subckt_params, subckt_param_names, subckt_param_values );
}
}
if ( num_subckt_params == 0 || !found_mult_param( num_subckt_params, subckt_param_names ) ) {
inp_fix_subckt_multiplier( p, num_subckt_params, subckt_param_names, subckt_param_values );
}
}
}
tfree(subckt_name );
if ( flag )
for (i=0; i < num_subckt_params; i++) {
tfree(subckt_param_names[i]);
tfree(subckt_param_values[i]);
}
for (i=0; i < num_inst_params; i++) {
tfree(inst_param_names[i]);
tfree(inst_param_values[i]);
}
}
tfree(subckt_name );
}
}
}
c = deck;
while ( c != NULL ) {
inst_line = c->li_line;
c = deck;
while ( c != NULL ) {
inst_line = c->li_line;
if ( *inst_line == '*' ) { c = c->li_next; continue; }
if ( ciprefix( "x", inst_line ) ) {
subckt_name = inp_get_subckt_name( inst_line );
for ( i = 0; i < num_subckt_w_params; i++ ) {
if ( strcmp( subckt_w_params[i], subckt_name ) == 0 ) {
sprintf( name_w_space, "%s ", subckt_name );
if ( *inst_line == '*' ) { c = c->li_next; continue; }
if ( ciprefix( "x", inst_line ) ) {
subckt_name = inp_get_subckt_name( inst_line );
for ( i = 0; i < num_subckt_w_params; i++ ) {
if ( strcmp( subckt_w_params[i], subckt_name ) == 0 ) {
sprintf( name_w_space, "%s ", subckt_name );
/* find .subckt line */
found_subckt = FALSE;
/* find .subckt line */
found_subckt = FALSE;
d = deck;
while ( d != NULL ) {
subckt_line = d->li_line;
if ( ciprefix( ".subckt", subckt_line ) ) {
for ( ; *subckt_line && !isspace(*subckt_line); subckt_line++ );
while ( isspace(*subckt_line) ) subckt_line++;
d = deck;
while ( d != NULL ) {
subckt_line = d->li_line;
if ( ciprefix( ".subckt", subckt_line ) ) {
for ( ; *subckt_line && !isspace(*subckt_line); subckt_line++ );
while ( isspace(*subckt_line) ) subckt_line++;
if ( strncmp( subckt_line, name_w_space, strlen(name_w_space) ) == 0 ) {
num_subckt_params = inp_get_params( subckt_line, subckt_param_names, subckt_param_values );
num_inst_params = inp_get_params( inst_line, inst_param_names, inst_param_values );
if ( strncmp( subckt_line, name_w_space, strlen(name_w_space) ) == 0 ) {
num_subckt_params = inp_get_params( subckt_line, subckt_param_names, subckt_param_values );
num_inst_params = inp_get_params( inst_line, inst_param_names, inst_param_values );
// make sure that if have inst params that one matches subckt
found_param_match = FALSE;
if ( num_inst_params == 0 ) found_param_match = TRUE;
else {
for ( j = 0; j < num_inst_params; j++ ) {
for ( k = 0; k < num_subckt_params; k++ ) {
if ( strcmp( subckt_param_names[k], inst_param_names[j] ) == 0 ) {
found_param_match = TRUE;
break;
}
}
if ( found_param_match ) break;
}
}
// make sure that if have inst params that one matches subckt
found_param_match = FALSE;
if ( num_inst_params == 0 ) found_param_match = TRUE;
else {
for ( j = 0; j < num_inst_params; j++ ) {
for ( k = 0; k < num_subckt_params; k++ ) {
if ( strcmp( subckt_param_names[k], inst_param_names[j] ) == 0 ) {
found_param_match = TRUE;
break;
}
}
if ( found_param_match ) break;
}
}
if ( !found_param_match ) {
// comment out .subckt and continue
while ( d != NULL && !ciprefix( ".ends", d->li_line ) ) { *(d->li_line) = '*'; d = d->li_next; }
*(d->li_line) = '*'; d = d->li_next; continue;
}
if ( !found_param_match ) {
// comment out .subckt and continue
while ( d != NULL && !ciprefix( ".ends", d->li_line ) ) { *(d->li_line) = '*'; d = d->li_next; }
*(d->li_line) = '*'; d = d->li_next; continue;
}
c->li_line = inp_fix_inst_line( inst_line,
num_subckt_params, subckt_param_names, subckt_param_values,
num_inst_params, inst_param_names, inst_param_values );
found_subckt = TRUE;
}
}
if ( found_subckt ) break;
d = d->li_next;
}
break;
}
c->li_line = inp_fix_inst_line( inst_line, num_subckt_params, subckt_param_names, subckt_param_values, num_inst_params, inst_param_names, inst_param_values );
found_subckt = TRUE;
for (i=0; i < num_subckt_params; i++) {
tfree(subckt_param_names[i]);
tfree(subckt_param_values[i]);
}
for (i=0; i < num_inst_params; i++) {
tfree(inst_param_names[i]);
tfree(inst_param_values[i]);
}
}
}
if ( found_subckt ) break;
d = d->li_next;
}
break;
}
}
tfree(subckt_name);
}
tfree(subckt_name);
}
c = c->li_next;
}
c = c->li_next;
}
}
static void

View File

@ -234,7 +234,7 @@ plotit(wordlist *wl, char *hcopy, char *devname)
{
/* All these things are static so that "samep" will work. */
static double *xcompress = NULL, *xindices = NULL;
static double *xlim = NULL, *ylim = NULL;
static double *xlim = NULL, *ylim = NULL, *xynull;
static double *xdelta = NULL, *ydelta = NULL;
static char *xlabel = NULL, *ylabel = NULL, *title = NULL;
static bool nointerp = FALSE;
@ -267,10 +267,14 @@ plotit(wordlist *wl, char *hcopy, char *devname)
/* First get the command line, without the limits.
Wii be used for zoomed windows */
wwl = wl_copy(wl);
(void) getlims(wwl, "xl", 2);
(void) getlims(wwl, "xlimit", 2);
(void) getlims(wwl, "yl", 2);
(void) getlims(wwl, "ylimit", 2);
xynull = getlims(wwl, "xl", 2); /* (void) getlims(wwl, "xl", 2); */
tfree(xynull); /*memory leak, if return value is not freed */
xynull = getlims(wwl, "xlimit", 2);
tfree(xynull); /*memory leak, if return value is not freed */
xynull = getlims(wwl, "yl", 2);
tfree(xynull); /*memory leak, if return value is not freed */
xynull = getlims(wwl, "ylimit", 2);
tfree(xynull); /*memory leak, if return value is not freed */
/* remove tile, xlabel, ylabel */
nxlabel = getword(wwl, "xlabel");
nylabel = getword(wwl, "ylabel");

View File

@ -206,7 +206,7 @@ printres(char *name)
#endif
bool yy = FALSE;
static long lastsec = 0, lastusec = 0;
struct variable *v;
struct variable *v, *vfree;
char *cpu_elapsed;
#ifdef XSPICE
@ -414,14 +414,14 @@ printres(char *name)
} else {
paramname = name;
}
v = if_getstat(ft_curckt->ci_ckt, paramname);
vfree = v = if_getstat(ft_curckt->ci_ckt, paramname);
if (paramname && v) {
/* end cider integration */
#else /* ~CIDER */
if (name && eq(name, "task"))
v = if_getstat(ft_curckt->ci_ckt, NULL);
vfree = v = if_getstat(ft_curckt->ci_ckt, NULL);
else
v = if_getstat(ft_curckt->ci_ckt, name);
vfree = v = if_getstat(ft_curckt->ci_ckt, name);
if (name && v) {
#endif
fprintf(cp_out, "%s = ", v->va_name);
@ -431,8 +431,10 @@ printres(char *name)
} else if (v) {
(void) putc('\n', cp_out);
while (v) {
wordlist *wlpr = cp_varwl(v);
fprintf(cp_out, "%s = ", v->va_name);
wl_print(cp_varwl(v), cp_out);
wl_print(wlpr, cp_out);
wl_free(wlpr);
(void) putc('\n', cp_out);
v = v->va_next;
}
@ -456,6 +458,7 @@ printres(char *name)
name);
fprintf(cp_err, "\tor no active circuit available\n");
}
if(vfree) free_struct_variable(vfree);
return;
}

View File

@ -230,7 +230,7 @@ cp_vset(char *varname, char type, char *value)
/* va_name is the same string */
u->va_type = v->va_type;
/* va_next left unchanged */
tfree(v->va_name);
// tfree(v->va_name);
tfree(v);
/* va: old version with memory leaks
w = u->va_next;
@ -252,6 +252,10 @@ cp_vset(char *varname, char type, char *value)
fprintf(cp_err, "cp_vset: Internal Error: bad US val %d\n", i);
break;
}
/* if (v_free) {
tfree(v->va_name);
tfree(v);
} */
tfree(copyvarname);
return;
}
@ -387,6 +391,24 @@ cp_setparse(wordlist *wl)
}
/* free the struct variable. The type of the union is given by va_type */
void
free_struct_variable(struct variable *v)
{
struct variable *tv, *tvv;
if(!v) return;
tv = v;
while(tv) {
tvv = tv->va_next;
if(tv->va_type == VT_LIST) free_struct_variable(tv->va_vlist);
if(tv->va_type == VT_STRING) tfree(tv->va_string);
tfree(tv);
tv = tvv;
}
}
void
cp_remvar(char *varname)
{
@ -510,27 +532,11 @@ cp_remvar(char *varname)
}
tfree(v->va_name);
tfree(v);
free_struct_variable(uv1);
return;
}
/* free the struct variable. The type of the union is given by va_type */
void
free_struct_variable(struct variable *v)
{
struct variable *tv, *tvv;
if(!v) return;
tv = v;
while(tv) {
tvv = tv->va_next;
if(tv->va_type == VT_LIST) free_struct_variable(tv->va_vlist);
if(tv->va_type == VT_STRING) tfree(tv->va_string);
tfree(tv);
tv = tvv;
}
}
/* Determine the value of a variable. Fail if the variable is unset,
* and if the type doesn't match, try and make it work... */
bool
@ -682,10 +688,11 @@ cp_variablesubst(wordlist *wlist)
nwl->wl_word = copy(buf);
}
(void) strcpy(tbuf, t); /* MW. Save t*/
if (!(wl = wl_splice(wl, nwl))) /*CDHW this frees wl CDHW*/
(void) strcpy(tbuf, t); /* MW. Save t*/
if (!(wl = wl_splice(wl, nwl))) {/*CDHW this frees wl CDHW*/
wl_free(nwl);
return (NULL);
}
/* This is bad... */
for (wlist = wl; wlist->wl_prev; wlist = wlist->wl_prev)
;

View File

@ -58,6 +58,6 @@ bool cp_getvar(char *name, int type, void *retval);
wordlist * cp_variablesubst(wordlist *wlist);
wordlist * vareval(char *string);
void cp_vprint(void);
void free_struct_variable(struct variable *v);
#endif /* _VARIABLE_H */