Browse Source

memory leaks: code improved

pre-master-46
h_vogt 17 years ago
parent
commit
8a4b560324
  1. 3
      ChangeLog
  2. 10
      src/frontend/numparam/spicenum.c
  3. 31
      src/spicelib/parser/inpgtok.c

3
ChangeLog

@ -1,7 +1,8 @@
2009-04-05 Holger Vogt 2009-04-05 Holger Vogt
* com_fft.c, inpcom.c, variable.c, variable.h, resource.c, cpitf.c, * com_fft.c, inpcom.c, variable.c, variable.h, resource.c, cpitf.c,
plotit.c:
plotit.c, inpgtok.c:
some more memory leaks removed some more memory leaks removed
spicenum.c: release of memory for dico->dyncategory corrected
2009-04-01 Dietmar Warning 2009-04-01 Dietmar Warning
* frontend/resource.c, misc/misc_time.c: init of rusage structure to prevent * frontend/resource.c, misc/misc_time.c: init of rusage structure to prevent

10
src/frontend/numparam/spicenum.c

@ -212,7 +212,6 @@ static void
modernizeex (char *s) modernizeex (char *s)
/* old style expressions &(..) and &id --> new style with braces. */ /* old style expressions &(..) and &id --> new style with braces. */
{ {
// Strbig (Llen, t);
int i, state, ls; int i, state, ls;
char c, d; char c, d;
Strbig (dynLlen, t); Strbig (dynLlen, t);
@ -290,7 +289,6 @@ transform (tdico * dico, char *s, unsigned char nostripping, char *u)
* 'B' netlist (or .model ?) line that had Braces killed * 'B' netlist (or .model ?) line that had Braces killed
*/ */
{ {
// Strbig (Llen, t);
char category; char category;
int i, k, a, n; int i, k, a, n;
Strbig (dynLlen, t); Strbig (dynLlen, t);
@ -389,7 +387,6 @@ static tdico *dico = NULL;
static void static void
putlogfile (char c, int num, char *t) putlogfile (char c, int num, char *t)
{ {
// Strbig (Llen, u);
Str (20, fname); Str (20, fname);
Strbig (dynLlen, u); Strbig (dynLlen, u);
if (dologfile) if (dologfile)
@ -439,8 +436,6 @@ nupa_init (char *srcfile)
dico->dyncategory[i] = '?'; dico->dyncategory[i] = '?';
} }
// sini (dico->srcfile, sizeof (dico->srcfile) - 4);
if (srcfile != NULL) if (srcfile != NULL)
scopy (dico->srcfile, srcfile); scopy (dico->srcfile, srcfile);
} }
@ -462,8 +457,9 @@ nupa_done (void)
for (i = dynmaxline ; i >= 0; i--) { for (i = dynmaxline ; i >= 0; i--) {
dispose ((void *) dico->dynrefptr[i]); dispose ((void *) dico->dynrefptr[i]);
dispose ((void *) dico->dyncategory[i]);
} }
dispose ((void *) dico->dynrefptr);
dispose ((void *) dico->dyncategory);
dispose ((void *) dico); dispose ((void *) dico);
dico = NULL; dico = NULL;
dispose ((void *) inst_dico); dispose ((void *) inst_dico);
@ -622,8 +618,6 @@ nupa_copy (char *s, int linenum)
- substitute placeholders for all {..} --> 10-digit numeric values. - substitute placeholders for all {..} --> 10-digit numeric values.
*/ */
{ {
// Strbig (Llen, u);
// Strbig (Llen, keywd);
char *t; char *t;
int ls; int ls;
char c, d; char c, d;

31
src/spicelib/parser/inpgtok.c

@ -27,6 +27,7 @@ int INPgetTok(char **line, char **token, int gobble)
{ {
char *point; char *point;
int signstate; int signstate;
int diffpoints;
/* scan along throwing away garbage characters until end of line /* scan along throwing away garbage characters until end of line
or a separation char is found */ or a separation char is found */
@ -94,7 +95,17 @@ int INPgetTok(char **line, char **token, int gobble)
} }
if (point == *line && *point) /* Weird items, 1 char */
diffpoints = point - *line;
if ((diffpoints < 1) && *point)
diffpoints = 1; /* Weird items, 1 char */
*token = (char *) tmalloc((1 + diffpoints)*sizeof(char));
if (!*token)
return (E_NOMEM);
(void) strncpy(*token, *line, diffpoints);
*(*token + diffpoints) = '\0';
*line = point;
/*
if (point == *line && *point)
point++; point++;
*token = (char *) MALLOC(1 + point - *line); *token = (char *) MALLOC(1 + point - *line);
if (!*token) if (!*token)
@ -102,7 +113,7 @@ int INPgetTok(char **line, char **token, int gobble)
(void) strncpy(*token, *line, point - *line); (void) strncpy(*token, *line, point - *line);
*(*token + (point - *line)) = '\0'; *(*token + (point - *line)) = '\0';
*line = point; *line = point;
*/
/* gobble garbage to next token */ /* gobble garbage to next token */
for (; **line != '\0'; (*line)++) { for (; **line != '\0'; (*line)++) {
if (**line == ' ') if (**line == ' ')
@ -139,6 +150,7 @@ int INPgetNetTok(char **line, char **token, int gobble)
{ {
char *point; char *point;
int signstate; int signstate;
int diffpoints;
/* scan along throwing away garbage characters until end of line /* scan along throwing away garbage characters until end of line
or a separation char is found */ or a separation char is found */
@ -181,7 +193,18 @@ int INPgetNetTok(char **line, char **token, int gobble)
} }
/* now copy found token into *token */ /* now copy found token into *token */
if (point == *line && *point) /* Weird items, 1 char */
diffpoints = point - *line;
if ((diffpoints < 1) && *point)
diffpoints = 1; /* Weird items, 1 char */
*token = (char *) tmalloc((1 + diffpoints)*sizeof(char));
if (!*token)
return (E_NOMEM);
(void) strncpy(*token, *line, diffpoints);
*(*token + diffpoints) = '\0';
*line = point;
/*
if (point == *line && *point)
point++; point++;
*token = (char *) MALLOC(1 + point - *line); *token = (char *) MALLOC(1 + point - *line);
if (!*token) if (!*token)
@ -189,7 +212,7 @@ int INPgetNetTok(char **line, char **token, int gobble)
(void) strncpy(*token, *line, point - *line); (void) strncpy(*token, *line, point - *line);
*(*token + (point - *line)) = '\0'; *(*token + (point - *line)) = '\0';
*line = point; *line = point;
*/
/* gobble garbage to next token */ /* gobble garbage to next token */
for (; **line != '\0'; (*line)++) { for (; **line != '\0'; (*line)++) {
if (**line == ' ') if (**line == ' ')

Loading…
Cancel
Save