[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests
From: |
Paul Eggert |
Subject: |
Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests |
Date: |
Thu, 08 Dec 2005 10:54:32 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
"Joel E. Denny" <address@hidden> writes:
> Unfortunately, I don't have a linux box set up, and I'm pretty sure
> valgrind requires the kernel. I've been meaning to set one up
> specifically for valgrind, but it won't be any time soon.
OK. Perhaps you don't need valgrind, since I can tell you its results.
valgrind reports that cxx-type.at contains test cases that leak memory,
and if you look at the test cases it's pretty obvious that they do.
Unfortunately when I tried to close the leaks (see below) I ended up
freeing storage more than once, and I suspect it's due to a GLR bug
(one that perhaps you're already fixing).
If you install this patch to tests/cxx-type.at, the test case should
fail nicely even if you're not using valgrind. I think the problem is
that error handling doesn't do free right.
By the way, should the action for "error ';'" free ($1)?
--- cxx-type.at 2005-07-24 00:24:22.000000000 -0700
+++ /home/eggert/junk/cxx-type.at 2005-12-07 22:38:01.000000000 -0800
@@ -39,7 +39,7 @@ $1
[ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
#define YYINITDEPTH 10
#define YYSTACKEXPANDABLE 1
- static char *format (char const *, ...);
+ static char *format (char const *, char *, char *);
struct YYLTYPE;
#if YYPURE
# if YYLSP_NEEDED
@@ -77,12 +77,13 @@ prog :
@2.first_line, @2.first_column,
@2.last_line, @2.last_column);])[
printf ("%s\n", ]$[2);
+ free (]$[2);
}
;
stmt : expr ';' $2 { $$ = ]$[1; }
| decl $3
- | error ';' { static char error_msg[] = "<error>"; $$ = error_msg; }
+ | error ';' { $$ = format ("<error>", 0, 0); }
| '@' { YYACCEPT; }
;
@@ -95,7 +96,8 @@ expr : ID
decl : TYPENAME declarator ';'
{ $$ = format ("<declare>(%s,%s)", ]$[1, ]$[2); }
| TYPENAME declarator '=' expr ';'
- { $$ = format ("<init-declare>(%s,%s,%s)", ]$[1, ]$[2,
]$[4); }
+ { $$ = format ("<init-declare>(%s,%s)", ]$[1,
+ format ("%s,%s", ]$[2, ]$[4)); }
;
declarator : ID
@@ -205,13 +207,12 @@ yyerror (ERROR_PARAMETERS)
static char *
-format (char const *form, ...)
+format (char const *form, char *arg1, char *arg2)
{
char buffer[1024];
- va_list args;
- va_start (args, form);
- vsprintf (buffer, form, args);
- va_end (args);
+ sprintf (buffer, form, arg1, arg2);
+ free (arg1);
+ free (arg2);
return strcpy ((char *) malloc (strlen (buffer) + 1), buffer);
}
- Bison bugs (memory leaks) found by valgrind in GLR-related tests, Paul Eggert, 2005/12/08
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Joel E. Denny, 2005/12/08
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests,
Paul Eggert <=
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Joel E. Denny, 2005/12/10
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Joel E. Denny, 2005/12/16
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Joel E. Denny, 2005/12/20
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Paul Eggert, 2005/12/21
- Re: Bison bugs (memory leaks) found by valgrind in GLR-related tests, Joel E. Denny, 2005/12/21