bison-patches
[Top][All Lists]
Advanced

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

Bison bugs (memory leaks) found by valgrind in GLR-related tests


From: Paul Eggert
Subject: Bison bugs (memory leaks) found by valgrind in GLR-related tests
Date: Wed, 07 Dec 2005 22:56:13 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

twlevo <address@hidden> writes:

> noticed if valgrind is configured in 
> tests/Makefile.am with the option
> '$(VALGRIND) --leak-check=full -q'
> some error messages in GLR tests 
> 127-135 appear.
>
> maybe some improvement needed?

I reproduced this problem by running the following command:

cd tests
./testsuite -v -d PREBISON='valgrind -q'  PREPARSER='valgrind --leak-check=full 
-q' 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

A lot of the cxx-type.at tests failed due to memory leaks (the tests
were: 127 128 129 130 131 132 133 134 135).  Perhaps Joel E. Denny or
Paul Hilfinger could look at those?  Some of them look like they might
be bugs in the GLR parser itself.

Some of the glr-regression.at tests failed.  This is due to the test
case code, not due to a bug in the GLR parser itself: the test case
has some memory leaks.  I installed the following patch to fix this.

2005-12-07  Paul Eggert  <address@hidden>

        * tests/glr-regression.at
        (Improper handling of embedded actions and dollar(-N) in GLR parsers):
        Close memory leak reported by twlevo.

--- glr-regression.at.~1.19.~   2005-10-30 17:16:32.000000000 -0800
+++ glr-regression.at   2005-12-07 21:44:22.000000000 -0800
@@ -120,7 +120,7 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
 /* Reported by S. Eken */
 
 %{
-  #define YYSTYPE char const *
+  #define YYSTYPE char *
 
   #include <ctype.h>
   #include <stdio.h>
@@ -138,9 +138,11 @@ command:
     's' var 't'
        { printf ("Variable: '%s'\n", $2); }
     'v' 'x' 'q'
+       { free ($2); }
   | 's' var_list 't' 'e'
-       { printf ("Varlist: '%s'\n", $2); }
+       { printf ("Varlist: '%s'\n", $2); free ($2); }
   | 's' var 't' var_printer 'x'
+       { free ($2); }
   ;
 
 var:
@@ -153,10 +155,10 @@ var_list:
     { $$ = $1; }
   | var ',' var_list
     {
-      char *s = (char *) malloc (strlen ($1) + 1 + strlen ($3) + 1);
-      strcpy (s, $1);
+      char *s = (char *) realloc ($1, strlen ($1) + 1 + strlen ($3) + 1);
       strcat (s, ",");
       strcat (s, $3);
+      free ($3);
       $$ = s;
     }
   ;
@@ -667,9 +669,9 @@ AT_DATA_GRAMMAR([glr-regr8.y],
 
 
 PortClause     : T_PORT InterfaceDeclaration T_PORT
-               { printf("%d/%d - %d/%d - %d/%d\n", 
-                        @1.first_column, @1.last_column, 
-                        @2.first_column, @2.last_column, 
+               { printf("%d/%d - %d/%d - %d/%d\n",
+                        @1.first_column, @1.last_column,
+                        @2.first_column, @2.last_column,
                         @3.first_column, @3.last_column); }
        ;
 
@@ -695,7 +697,7 @@ void yyerror(const char *msg)
 
 static int lexIndex;
 
-int yylex() 
+int yylex (void)
 {
   lexIndex += 1;
   switch (lexIndex)
@@ -714,7 +716,7 @@ int yylex() 
 }
 
 int
-main (void) 
+main (void)
 {
   yyparse();
   return 0;
@@ -726,7 +728,7 @@ AT_CHECK([[bison -o glr-regr8.c glr-regr
 ])
 AT_COMPILE([glr-regr8])
 
-AT_CHECK([[./glr-regr8]], 0, 
+AT_CHECK([[./glr-regr8]], 0,
 [empty: 9/9
 1/9 - 9/9 - 13/17
 ],




reply via email to

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