m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU M4 source repository branch, master, updated. cvs-readonly-15-


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, master, updated. cvs-readonly-15-gb4a3bec
Date: Tue, 13 Nov 2007 21:40:22 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=b4a3bec5f9cfec145db6f4cb281ba1673ca6bfc6

The branch, master has been updated
       via  b4a3bec5f9cfec145db6f4cb281ba1673ca6bfc6 (commit)
      from  e339c7dd5269ea4f5da63606ec6348ee3e6fe7c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b4a3bec5f9cfec145db6f4cb281ba1673ca6bfc6
Author: Eric Blake <address@hidden>
Date:   Tue Nov 13 14:08:16 2007 -0700

    Fix memory leak in tail recursion.
    
    * m4/input.c (pop_input): Add flag parameter and return type.
    (next_char): Adjust caller.
    (m4_push_string_init): Let go of memory earlier.
    
    Signed-off-by: Eric Blake <address@hidden>
    (cherry picked from commit 6bfe1ba306cacd8d9316647f3b9f276cf56b31a8)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog  |    7 +++++++
 m4/input.c |   34 ++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ce2080b..b55fe54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-11-13  Eric Blake  <address@hidden>
+
+       Fix memory leak in tail recursion.
+       * m4/input.c (pop_input): Add flag parameter and return type.
+       (next_char): Adjust caller.
+       (m4_push_string_init): Let go of memory earlier.
+
 2007-11-07  Eric Blake  <address@hidden>
 
        * tests/macros.at (Rescanning macros): Test more corner cases.
diff --git a/m4/input.c b/m4/input.c
index 646a169..a8c4f87 100644
--- a/m4/input.c
+++ b/m4/input.c
@@ -109,7 +109,7 @@ static      void    init_builtin_token      (m4 *, 
m4_symbol_value *);
 static bool    match_input             (m4 *, const char *, bool);
 static int     next_char               (m4 *, bool);
 static int     peek_char               (m4 *);
-static void    pop_input               (m4 *);
+static bool    pop_input               (m4 *, bool);
 static void    unget_input             (int);
 static bool    consume_syntax          (m4 *, m4_obstack *, unsigned int);
 
@@ -496,12 +496,11 @@ string_print (m4_input_block *me, m4 *context, m4_obstack 
*obs)
 m4_obstack *
 m4_push_string_init (m4 *context)
 {
-  if (next != NULL)
-    {
-      assert (!"INTERNAL ERROR: recursive m4_push_string!");
-      abort ();
-    }
+  /* Free any memory occupied by completely parsed input.  */
+  assert (!next);
+  while (isp && pop_input (context, false));
 
+  /* Reserve the next location on the obstack.  */
   next = (m4_input_block *) obstack_alloc (current_input,
                                           sizeof (m4_input_block));
   next->funcs = &string_funcs;
@@ -673,15 +672,25 @@ m4_push_wrapup (m4 *context, const char *s)
 }
 
 
-/* The function pop_input () pops one level of input sources.  The
-   current_file and current_line are restored as needed.  */
-static void
-pop_input (m4 *context)
+/* The function pop_input () pops one level of input sources.  If
+   CLEANUP, the current_file and current_line are restored as needed.
+   The return value is false if cleanup is still required, or if the
+   current input source is not at the end.  */
+static bool
+pop_input (m4 *context, bool cleanup)
 {
   m4_input_block *tmp = isp->prev;
 
+  assert (isp);
+  if (isp->funcs->peek_func (isp) != CHAR_RETRY)
+    return false;
+
   if (isp->funcs->clean_func != NULL)
-    isp->funcs->clean_func (isp, context);
+    {
+      if (!cleanup)
+       return false;
+      isp->funcs->clean_func (isp, context);
+    }
 
   if (tmp != NULL)
     {
@@ -691,6 +700,7 @@ pop_input (m4 *context)
 
   isp = tmp;
   input_change = true;
+  return true;
 }
 
 /* To switch input over to the wrapup stack, main () calls pop_wrapup.
@@ -784,7 +794,7 @@ next_char (m4 *context, bool retry)
        }
 
       /* End of input source --- pop one level.  */
-      pop_input (context);
+      pop_input (context, true);
     }
 }
 


hooks/post-receive
--
GNU M4 source repository




reply via email to

[Prev in Thread] Current Thread [Next in Thread]