bug-bison
[Top][All Lists]
Advanced

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

Re: Bison 1.30: memory leak in yyparse


From: Akim Demaille
Subject: Re: Bison 1.30: memory leak in yyparse
Date: 09 Nov 2001 19:08:15 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence)

In fact, how about this patch instead?

Index: src/bison.simple
===================================================================
RCS file: /cvsroot/bison/bison/src/bison.simple,v
retrieving revision 1.53.2.3
diff -u -u -r1.53.2.3 bison.simple
--- src/bison.simple 2001/10/10 14:59:46 1.53.2.3
+++ src/bison.simple 2001/11/09 18:09:40
@@ -77,9 +77,22 @@
 #endif
 
 #if YYSTACK_USE_ALLOCA
-# define YYSTACK_ALLOC alloca
+# define YYSTACK_REALLOC(Type, What, Old, Array)                       \
+do {                                                                   \
+  What = (Type *) malloc (yystacksize * sizeof (Type));                \
+  __yy_memcpy ((char *) What, (char *) Old,                            \
+              (size) * (unsigned int) sizeof (Type));                  \
+  yyfree_stacks = 1;                                                   \
+  if (Old != Array)                                                    \
+    free (Old);                                                        \
+} while (0)
 #else
-# define YYSTACK_ALLOC malloc
+# define YYSTACK_REALLOC(Type, What, Old, Array)                       \
+do {                                                                   \
+  What = (Type *) alloca (yystacksize * sizeof (Type));                \
+  __yy_memcpy ((char *) What, (char *) Old,                            \
+              (size) * (unsigned int) sizeof (*What));                 \
+} while (0)
 #endif
 
 #define yyerrok                (yyerrstatus = 0)
@@ -420,19 +433,11 @@
       yystacksize *= 2;
       if (yystacksize > YYMAXDEPTH)
        yystacksize = YYMAXDEPTH;
-# if !YYSTACK_USE_ALLOCA
-      yyfree_stacks = 1;
-# endif
-      yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
-      __yy_memcpy ((char *)yyss, (char *)yyss1,
-                  size * (unsigned int) sizeof (*yyssp));
-      yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
-      __yy_memcpy ((char *)yyvs, (char *)yyvs1,
-                  size * (unsigned int) sizeof (*yyvsp));
+
+      YYSTACK_REALLOC (short, yyss, yyss1, yyssa);
+      YYSTACK_REALLOC (YYSTYPE, yyvs, yyvs1, yyvsa);
 # if YYLSP_NEEDED
-      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
-      __yy_memcpy ((char *)yyls, (char *)yyls1,
-                  size * (unsigned int) sizeof (*yylsp));
+      YYSTACK_REALLOC (YYLTYPE, yyls, yyls1, yylsa);
 # endif
 #endif /* no yyoverflow */
 



reply via email to

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