Fix some memory leaks, found with valgrind.

This commit is contained in:
Paul Smith 2009-09-26 23:01:55 +00:00
parent 48045f99e5
commit 44ac2cdb4d
3 changed files with 23 additions and 5 deletions

View file

@ -1,3 +1,9 @@
2009-09-26 Paul Smith <psmith@gnu.org>
* read.c (record_files): Free FILENAMES chain for implicit rules.
* function.c (string_glob): Free NAME in the nameseq chain.
2009-09-25 Boris Kolpackov <boris@codesynthesis.com> 2009-09-25 Boris Kolpackov <boris@codesynthesis.com>
* implicit.c (pattern_search): Terminate early if we haven't * implicit.c (pattern_search): Terminate early if we haven't

View file

@ -382,6 +382,7 @@ string_glob (char *line)
idx += len; idx += len;
result[idx++] = ' '; result[idx++] = ' ';
free (chain->name);
free (chain); free (chain);
chain = next; chain = next;
} }

21
read.c
View file

@ -566,8 +566,8 @@ eval (struct ebuffer *ebuf, int set_default)
record_files (filenames, pattern, pattern_percent, depstr, \ record_files (filenames, pattern, pattern_percent, depstr, \
cmds_started, commands, commands_idx, two_colon, \ cmds_started, commands, commands_idx, two_colon, \
&fi); \ &fi); \
filenames = 0; \
} \ } \
filenames = 0; \
commands_idx = 0; \ commands_idx = 0; \
no_targets = 0; \ no_targets = 0; \
pattern = 0; \ pattern = 0; \
@ -1935,8 +1935,13 @@ record_files (struct nameseq *filenames, const char *pattern,
if (pattern != 0) if (pattern != 0)
fatal (flocp, _("mixed implicit and static pattern rules")); fatal (flocp, _("mixed implicit and static pattern rules"));
/* Create an array of target names */ /* Count the targets to create an array of target names.
for (c = 1, nextf = filenames->next; nextf; ++c, nextf = nextf->next) We already have the first one. */
nextf = filenames->next;
free (filenames);
filenames = nextf;
for (c = 1; nextf; ++c, nextf = nextf->next)
; ;
targets = xmalloc (c * sizeof (const char *)); targets = xmalloc (c * sizeof (const char *));
target_pats = xmalloc (c * sizeof (const char *)); target_pats = xmalloc (c * sizeof (const char *));
@ -1944,9 +1949,10 @@ record_files (struct nameseq *filenames, const char *pattern,
targets[0] = name; targets[0] = name;
target_pats[0] = implicit_percent; target_pats[0] = implicit_percent;
for (c = 1, nextf = filenames->next; nextf; ++c, nextf = nextf->next) c = 1;
while (filenames)
{ {
name = nextf->name; name = filenames->name;
implicit_percent = find_percent_cached (&name); implicit_percent = find_percent_cached (&name);
if (implicit_percent == 0) if (implicit_percent == 0)
@ -1954,6 +1960,11 @@ record_files (struct nameseq *filenames, const char *pattern,
targets[c] = name; targets[c] = name;
target_pats[c] = implicit_percent; target_pats[c] = implicit_percent;
++c;
nextf = filenames->next;
free (filenames);
filenames = nextf;
} }
create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1); create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1);