m4-patches
[Top][All Lists]
Advanced

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

FYI: 30-gary-free-memory-reference-fix.patch


From: Gary V. Vaughan
Subject: FYI: 30-gary-free-memory-reference-fix.patch
Date: Tue, 16 Oct 2001 03:38:38 +0100
User-agent: Mutt/1.3.16i

This patch fixes the SEGV in CVS autoconf.  However, I am not entirely
happy with the fix:  it seems to me that m4_symtab_apply should be
talking a copy of the symbol name to pass into its callback function
(m4_symbol_destroy in this case) rather than making each callback
responsible for protecting the memory it is passed.  I have spent all
evening trying to figure out why the autoconf test suite fails
spectacularly when I do that though... if you can see why this patch
works, but my preferred fix does not, please tell me!!!  I imagine that
one of the other callback functions passed to m4_symtab_apply is annoyed
by not having the actual hash table key address for its name parameter,
but I couldn't prove it.

Bah!

Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>

        * m4/symtab.c (m4_symbol_destroy): This function calls
        m4_symbol_popdef, which recycles a symbols memory when the last
        definition is popped.  Since we were passing the address of the
        symbol name found in the symbol table, and it was being removed
        partway through m4_symbol_destroy() we were referencing freed
        memory for the balance of the function.  Now we take a copy of the
        symbol name tring and use that as a key into the symbol
        table... that way if the original symbol name is freed, the copy
        is still valid.

Index: m4/symtab.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/symtab.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 symtab.c
--- m4/symtab.c 2001/10/12 19:57:29 1.26
+++ m4/symtab.c 2001/10/16 02:27:41
@@ -80,6 +80,7 @@ m4_symtab_apply (m4_symtab_apply_func *f
     {
       const char *name = (const char *) m4_hash_iterator_key (place);
       m4_symbol *symbol = (m4_symbol *) m4_hash_iterator_value (place);
+
       result = (*func) (name, symbol, data);
 
       if (result != 0)
@@ -148,10 +149,14 @@ m4_symtab_exit (void)
 static int
 m4_symbol_destroy (const char *name, m4_symbol *symbol, void *data)
 {
+  char *key = xstrdup (name);
+
   SYMBOL_TRACED (symbol) = FALSE;
+
+  while (key && m4_hash_lookup (m4_symtab, key))
+    m4_symbol_popdef (key);
 
-  while (m4_hash_lookup (m4_symtab, name))
-    m4_symbol_popdef (name);
+  XFREE (key);
 
   return 0;
 }

-- 
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/



reply via email to

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