[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Valgrind and Bison memory leaks
From: |
Joel E. Denny |
Subject: |
Re: Valgrind and Bison memory leaks |
Date: |
Thu, 9 Nov 2006 13:17:56 -0500 (EST) |
On Wed, 8 Nov 2006, Joel E. Denny wrote:
> On Wed, 8 Nov 2006, Paul Eggert wrote:
>
> > OK, I reviewed that patch and installed the following
> > slightly-different one. The main thing was that funny union, which
> > confused me, and so I replaced it with a char const * value and a char
> > * storage pointer (which might be null, but can be freed).
>
> Thanks, I'll look it over later today.
I commited the following to address a few minor issues.
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1601
diff -p -u -r1.1601 ChangeLog
--- ChangeLog 8 Nov 2006 20:41:55 -0000 1.1601
+++ ChangeLog 9 Nov 2006 18:13:02 -0000
@@ -1,3 +1,15 @@
+2006-11-09 Joel E. Denny <address@hidden>
+
+ * src/files.c (tr): Change return type to void.
+ * src/muscle_tab.c (muscle_insert): Free storage in case muscle_grow
+ has been called previously for the same key.
+ (muscle_find): Return storage instead of value so that
+ --enable-gcc-warnings doesn't produce warnings that the return discards
+ const. aver that the value and storage are the same since storage
+ could potentially be NULL when value is not.
+ * tests/testsuite.at (AT_CHECK): Treat an unspecified exit value the
+ same as 0.
+
2006-11-08 Paul Eggert <address@hidden>
* bootstrap.conf (excluded_files): Exclude m4/codeset.m4 (undoing
Index: src/files.c
===================================================================
RCS file: /sources/bison/bison/src/files.c,v
retrieving revision 1.98
diff -p -u -r1.98 files.c
--- src/files.c 8 Nov 2006 20:28:57 -0000 1.98
+++ src/files.c 9 Nov 2006 18:13:02 -0000
@@ -137,7 +137,7 @@ xfclose (FILE *ptr)
`------------------------------------------------------------------*/
/* In the string S, replace all characters FROM by TO. */
-static char *
+static void
tr (char *s, char from, char to)
{
for (; *s; s++)
Index: src/muscle_tab.c
===================================================================
RCS file: /sources/bison/bison/src/muscle_tab.c,v
retrieving revision 1.40
diff -p -u -r1.40 muscle_tab.c
--- src/muscle_tab.c 8 Nov 2006 20:28:57 -0000 1.40
+++ src/muscle_tab.c 9 Nov 2006 18:13:02 -0000
@@ -123,9 +123,11 @@ muscle_insert (char const *key, char con
entry = xmalloc (sizeof *entry);
entry->key = key;
hash_insert (muscle_table, entry);
- entry->storage = NULL;
}
+ else
+ free (entry->storage);
entry->value = value;
+ entry->storage = NULL;
}
@@ -207,9 +209,11 @@ void muscle_pair_list_grow (const char *
obstack_free (&muscle_obstack, pair);
}
-/*-------------------------------.
-| Find the value of muscle KEY. |
-`-------------------------------*/
+/*----------------------------------------------------------------------------.
+| Find the value of muscle KEY. Abort if muscle_insert was invoked more |
+| recently than muscle_grow for KEY since muscle_find can't return a |
+| char const *. |
+`----------------------------------------------------------------------------*/
char *
muscle_find (const char *key)
@@ -219,7 +223,12 @@ muscle_find (const char *key)
probe.key = key;
result = hash_lookup (muscle_table, &probe);
- return result ? result->value : NULL;
+ if (result)
+ {
+ aver (result->value == result->storage);
+ return result->storage;
+ }
+ return NULL;
}
Index: tests/testsuite.at
===================================================================
RCS file: /sources/bison/bison/tests/testsuite.at,v
retrieving revision 1.29
diff -p -u -r1.29 testsuite.at
--- tests/testsuite.at 8 Nov 2006 20:28:57 -0000 1.29
+++ tests/testsuite.at 9 Nov 2006 18:13:02 -0000
@@ -25,7 +25,7 @@ m4_pushdef([ORIGINAL_AT_CHECK], m4_defn(
m4_pushdef([AT_CHECK],
[ORIGINAL_AT_CHECK(
m4_if(m4_quote(m4_substr(m4_quote($1), 0, 5)), [bison],
- m4_if([$2], [0], [],
+ m4_if([$2], [0], [], [$2], [], [],
[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary
--show-reachable=no"; export VALGRIND_OPTS; ]]))$@)])
# Testing resistance to user bugs.