Some memory leak cleanups (found with valgrind).

This commit is contained in:
Paul Smith 2006-02-14 15:42:17 +00:00
parent df267b31c5
commit 86af3872a9
7 changed files with 85 additions and 48 deletions

View File

@ -1,3 +1,21 @@
2006-02-14 Paul D. Smith <psmith@gnu.org>
* read.c (eval): Even if the included filenames expands to the
empty string we still need to free the allocated buffer.
* implicit.c (pattern_search): If we allocated a variable set for
an impossible file, free it.
* variable.c (free_variable_set): New function.
* variable.h: Declare it.
* read.c (read_all_makefiles): Makefile names are kept in the
strcache, so there's never any need to alloc/free them.
(eval): Ditto.
* main.c (main): Add "archives" to the .FEATURES variable if
archive support is enabled.
* doc/make.texi (Special Variables): Document it.
2006-02-13 Paul D. Smith <psmith@gnu.org> 2006-02-13 Paul D. Smith <psmith@gnu.org>
* implicit.c (pattern_search): Add checking for DOS pathnames to * implicit.c (pattern_search): Add checking for DOS pathnames to

View File

@ -1369,28 +1369,33 @@ Expands to a list of special features supported by this version of
@code{make}. Possible values include: @code{make}. Possible values include:
@table @samp @table @samp
@item target-specific
Supports target-specific and pattern-specific variable assignments.
@xref{Target-specific, ,Target-specific Variable Values}.
@item order-only @item archives
Supports order-only prerequisites. @xref{Prerequisite Types, ,Types Supports @code{ar} (archive) files using special filename syntax.
of Prerequisites}. @xref{Archives, ,Using @code{make} to Update Archive Files}.
@item second-expansion @item check-symlink
Supports secondary expansion of prerequisite lists. Supports the @code{-L} (@code{--check-symlink-times}) flag.
@xref{Options Summary, ,Summary of Options}.
@item jobserver
Supports ``job server'' enhanced parallel builds. @xref{Parallel,
,Parallel Execution}.
@item else-if @item else-if
Supports ``else if'' non-nested conditionals. @xref{Conditional Supports ``else if'' non-nested conditionals. @xref{Conditional
Syntax, ,Syntax of Conditionals}. Syntax, ,Syntax of Conditionals}.
@item check-symlink @item jobserver
Supports the @code{-L} (@code{--check-symlink-times}) flag. Supports ``job server'' enhanced parallel builds. @xref{Parallel,
@xref{Options Summary, ,Summary of Options}. ,Parallel Execution}.
@item second-expansion
Supports secondary expansion of prerequisite lists.
@item order-only
Supports order-only prerequisites. @xref{Prerequisite Types, ,Types
of Prerequisites}.
@item target-specific
Supports target-specific and pattern-specific variable assignments.
@xref{Target-specific, ,Target-specific Variable Values}.
@end table @end table
@ -2047,10 +2052,10 @@ directory for each user (such as MS-DOS or MS-Windows), this
functionality can be simulated by setting the environment variable functionality can be simulated by setting the environment variable
@var{HOME}.@refill @var{HOME}.@refill
Wildcard expansion happens automatically in targets, in prerequisites, Wildcard expansion is performed by @code{make} automatically in
and in commands (where the shell does the expansion). In other targets and in prerequisites. In commands the shell is responsible
contexts, wildcard expansion happens only if you request it explicitly for wildcard expansion. In other contexts, wildcard expansion happens
with the @code{wildcard} function. only if you request it explicitly with the @code{wildcard} function.
The special significance of a wildcard character can be turned off by The special significance of a wildcard character can be turned off by
preceding it with a backslash. Thus, @file{foo\*bar} would refer to a preceding it with a backslash. Thus, @file{foo\*bar} would refer to a

View File

@ -77,24 +77,25 @@ struct idep
}; };
static void static void
free_idep_chain (struct idep* p) free_idep_chain (struct idep *p)
{ {
register struct idep* n; struct idep *n;
register struct file *f; struct file *f;
for (; p != 0; p = n) for (; p != 0; p = n)
{ {
n = p->next; n = p->next;
if (p->name) if (p->name)
free (p->name);
f = p->intermediate_file;
if (f != 0)
{ {
free (p->name); /* if (f->variables)
free_variable_set (f->variables); */
f = p->intermediate_file; if (f->stem < f->name
|| f->stem > f->name + strlen (f->name))
if (f != 0
&& (f->stem < f->name
|| f->stem > f->name + strlen (f->name)))
free (f->stem); free (f->stem);
} }
@ -742,6 +743,8 @@ pattern_search (struct file *file, int archive,
/* If we have tried to find P as an intermediate /* If we have tried to find P as an intermediate
file and failed, mark that name as impossible file and failed, mark that name as impossible
so we won't go through the search again later. */ so we won't go through the search again later. */
if (intermediate_file->variables)
free_variable_set (intermediate_file->variables);
file_impossible (name); file_impossible (name);
} }

4
main.c
View File

@ -1110,6 +1110,10 @@ main (int argc, char **argv, char **envp)
define_variable (".FEATURES", 9, define_variable (".FEATURES", 9,
"target-specific order-only second-expansion else-if", "target-specific order-only second-expansion else-if",
o_default, 0); o_default, 0);
#ifndef NO_ARCHIVES
do_variable_definition (NILF, ".FEATURES", "archives",
o_default, f_append, 0);
#endif
#ifdef MAKE_JOBSERVER #ifdef MAKE_JOBSERVER
do_variable_definition (NILF, ".FEATURES", "jobserver", do_variable_definition (NILF, ".FEATURES", "jobserver",
o_default, f_append, 0); o_default, f_append, 0);

19
read.c
View File

@ -186,10 +186,7 @@ read_all_makefiles (char **makefiles)
{ {
if (*p != '\0') if (*p != '\0')
*p++ = '\0'; *p++ = '\0';
name = xstrdup (name); eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
if (eval_makefile (name,
RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE) < 2)
free (name);
} }
free (value); free (value);
@ -810,7 +807,10 @@ eval (struct ebuffer *ebuf, int set_default)
/* If no filenames, it's a no-op. */ /* If no filenames, it's a no-op. */
if (*p == '\0') if (*p == '\0')
continue; {
free (p);
continue;
}
/* Parse the list of file names. */ /* Parse the list of file names. */
p2 = p; p2 = p;
@ -840,12 +840,9 @@ eval (struct ebuffer *ebuf, int set_default)
r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
| (noerror ? RM_DONTCARE : 0))); | (noerror ? RM_DONTCARE : 0)));
if (!r) if (!r && !noerror)
{ error (fstart, "%s: %s", name, strerror (errno));
if (!noerror) free (name);
error (fstart, "%s: %s", name, strerror (errno));
free (name);
}
} }
/* Restore conditional state. */ /* Restore conditional state. */

View File

@ -539,14 +539,6 @@ initialize_file_variables (struct file *file, int reading)
/* Pop the top set off the current variable set list, /* Pop the top set off the current variable set list,
and free all its storage. */ and free all its storage. */
static void
free_variable_name_and_value (const void *item)
{
struct variable *v = (struct variable *) item;
free (v->name);
free (v->value);
}
struct variable_set_list * struct variable_set_list *
create_new_variable_set (void) create_new_variable_set (void)
{ {
@ -565,6 +557,23 @@ create_new_variable_set (void)
return setlist; return setlist;
} }
static void
free_variable_name_and_value (const void *item)
{
struct variable *v = (struct variable *) item;
free (v->name);
free (v->value);
}
void
free_variable_set (struct variable_set_list *list)
{
hash_map (&list->set->table, free_variable_name_and_value);
hash_free (&list->set->table, 1);
free ((char *) list->set);
free ((char *) list);
}
/* Create a new variable set and push it on the current setlist. /* Create a new variable set and push it on the current setlist.
If we're pushing a global scope (that is, the current scope is the global If we're pushing a global scope (that is, the current scope is the global
scope) then we need to "push" it the other way: file variable sets point scope) then we need to "push" it the other way: file variable sets point

View File

@ -136,6 +136,7 @@ extern char *recursively_expand_for_file PARAMS ((struct variable *v,
/* variable.c */ /* variable.c */
extern struct variable_set_list *create_new_variable_set PARAMS ((void)); extern struct variable_set_list *create_new_variable_set PARAMS ((void));
extern void free_variable_set PARAMS ((struct variable_set_list *));
extern struct variable_set_list *push_new_variable_scope PARAMS ((void)); extern struct variable_set_list *push_new_variable_scope PARAMS ((void));
extern void pop_variable_scope PARAMS ((void)); extern void pop_variable_scope PARAMS ((void));
extern void define_automatic_variables PARAMS ((void)); extern void define_automatic_variables PARAMS ((void));