]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Some memory leak cleanups (found with valgrind).
authorPaul Smith <psmith@gnu.org>
Tue, 14 Feb 2006 15:42:17 +0000 (15:42 +0000)
committerPaul Smith <psmith@gnu.org>
Tue, 14 Feb 2006 15:42:17 +0000 (15:42 +0000)
ChangeLog
doc/make.texi
implicit.c
main.c
read.c
variable.c
variable.h

index 52f7340a6ce8f519968dbc5794711dc6d6fb0d14..24732d274d4c447a8e7000fceb23175f4af1915e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * implicit.c (pattern_search): Add checking for DOS pathnames to
index a99e9ad337547b74b51850d58c28434a30905b8b..c73649fb9a9bc6c9336f1e155b8f9be7bfbf2c4c 100644 (file)
@@ -1369,28 +1369,33 @@ Expands to a list of special features supported by this version of
 @code{make}.  Possible values include:
 
 @table @samp
-@item target-specific
-Supports target-specific and pattern-specific variable assignments.
-@xref{Target-specific, ,Target-specific Variable Values}.
 
-@item order-only
-Supports order-only prerequisites.  @xref{Prerequisite Types, ,Types
-of Prerequisites}.
+@item archives
+Supports @code{ar} (archive) files using special filename syntax.
+@xref{Archives, ,Using @code{make} to Update Archive Files}.
 
-@item second-expansion
-Supports secondary expansion of prerequisite lists.
+@item check-symlink
+Supports the @code{-L} (@code{--check-symlink-times}) flag.
+@xref{Options Summary, ,Summary of Options}.
+
+@item else-if
+Supports ``else if'' non-nested conditionals.  @xref{Conditional
+Syntax, ,Syntax of Conditionals}.
 
 @item jobserver
 Supports ``job server'' enhanced parallel builds.  @xref{Parallel,
 ,Parallel Execution}.
 
-@item else-if
-Supports ``else if'' non-nested conditionals.  @xref{Conditional
-Syntax, ,Syntax of Conditionals}.
+@item second-expansion
+Supports secondary expansion of prerequisite lists.
 
-@item check-symlink
-Supports the @code{-L} (@code{--check-symlink-times}) flag.
-@xref{Options Summary, ,Summary of Options}.
+@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
 
@@ -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
 @var{HOME}.@refill
 
-Wildcard expansion happens automatically in targets, in prerequisites,
-and in commands (where the shell does the expansion).  In other
-contexts, wildcard expansion happens only if you request it explicitly
-with the @code{wildcard} function.
+Wildcard expansion is performed by @code{make} automatically in
+targets and in prerequisites.  In commands the shell is responsible
+for wildcard expansion.  In other contexts, wildcard expansion happens
+only if you request it explicitly with the @code{wildcard} function.
 
 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
index 7b34fba69d6e4b903f2b672fe116a0e4728c7238..d7c140a431d5105a6e42a3c89ee3932275297a0a 100644 (file)
@@ -77,24 +77,25 @@ struct idep
 };
 
 static void
-free_idep_chain (struct idepp)
+free_idep_chain (struct idep *p)
 {
-  register struct idep* n;
-  register struct file *f;
+  struct idep *n;
+  struct file *f;
 
   for (; p != 0; p = n)
     {
       n = p->next;
 
       if (p->name)
-        {
-          free (p->name);
-
-          f = p->intermediate_file;
+        free (p->name);
 
-          if (f != 0
-              && (f->stem < f->name
-                  || f->stem > f->name + strlen (f->name)))
+      f = p->intermediate_file;
+      if (f != 0)
+        {
+          /*          if (f->variables)
+                      free_variable_set (f->variables); */
+          if (f->stem < f->name
+              || f->stem > f->name + strlen (f->name))
             free (f->stem);
         }
 
@@ -742,6 +743,8 @@ pattern_search (struct file *file, int archive,
                   /* If we have tried to find P as an intermediate
                      file and failed, mark that name as impossible
                      so we won't go through the search again later.  */
+                  if (intermediate_file->variables)
+                    free_variable_set (intermediate_file->variables);
                   file_impossible (name);
                 }
 
diff --git a/main.c b/main.c
index 82fe46f328064831fc1aeb75765e5a5483fdf546..a645e44c272bfa2f2e51f994ddc0a237451068b9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1110,6 +1110,10 @@ main (int argc, char **argv, char **envp)
   define_variable (".FEATURES", 9,
                    "target-specific order-only second-expansion else-if",
                    o_default, 0);
+#ifndef NO_ARCHIVES
+  do_variable_definition (NILF, ".FEATURES", "archives",
+                          o_default, f_append, 0);
+#endif
 #ifdef MAKE_JOBSERVER
   do_variable_definition (NILF, ".FEATURES", "jobserver",
                           o_default, f_append, 0);
diff --git a/read.c b/read.c
index 82bc253dec7909ad35740f9c88c31f327743e1be..0c78c7f482946bbe36bcd3f948c7cbc46da1667b 100644 (file)
--- a/read.c
+++ b/read.c
@@ -186,10 +186,7 @@ read_all_makefiles (char **makefiles)
       {
        if (*p != '\0')
          *p++ = '\0';
-        name = xstrdup (name);
-       if (eval_makefile (name,
-                           RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE) < 2)
-          free (name);
+       eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
       }
 
     free (value);
@@ -810,7 +807,10 @@ eval (struct ebuffer *ebuf, int set_default)
 
           /* If no filenames, it's a no-op.  */
          if (*p == '\0')
-            continue;
+            {
+              free (p);
+              continue;
+            }
 
          /* Parse the list of file names.  */
          p2 = p;
@@ -840,12 +840,9 @@ eval (struct ebuffer *ebuf, int set_default)
 
               r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
                                         | (noerror ? RM_DONTCARE : 0)));
-             if (!r)
-                {
-                  if (!noerror)
-                    error (fstart, "%s: %s", name, strerror (errno));
-                  free (name);
-                }
+             if (!r && !noerror)
+                error (fstart, "%s: %s", name, strerror (errno));
+              free (name);
            }
 
          /* Restore conditional state.  */
index 54ac046b56cb610a71c58be6af39d5d019d14ddf..0ea71cdbf34f4f49ece9ff697ea1b0d3ebd0df56 100644 (file)
@@ -539,14 +539,6 @@ initialize_file_variables (struct file *file, int reading)
 /* Pop the top set off the current variable set list,
    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 *
 create_new_variable_set (void)
 {
@@ -565,6 +557,23 @@ create_new_variable_set (void)
   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.
    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
index 6b20152f8d16decc9ea8bbb6917ad320bede4e96..46b18fad94f06e58ed084ce0fad6315c12fdafcf 100644 (file)
@@ -136,6 +136,7 @@ extern char *recursively_expand_for_file PARAMS ((struct variable *v,
 
 /* variable.c */
 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 void pop_variable_scope PARAMS ((void));
 extern void define_automatic_variables PARAMS ((void));