bug-bison
[Top][All Lists]
Advanced

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

calc++ example leaks


From: Sander Brandenburg
Subject: calc++ example leaks
Date: Sun, 27 Aug 2006 19:31:30 +0200

Hi,

I encountered memory leaks in the calc++ example from the bison manual. I
verified it on the calc++ example that's in the bison-2.3 tarball.

Below is a fix for the memory leaks. I'm only not sure the way I solve it is
good practice, because keeping track of what needs to be deleted looks
rather cumbersome.

Cheers,
Sander Brandenburg

diff -r -u calc++-orig/calc++-parser.yy calc++/calc++-parser.yy
--- calc++-orig/calc++-parser.yy        2006-08-27 19:17:19.000000000 +0200
+++ calc++/calc++-parser.yy     2006-08-27 19:20:05.000000000 +0200
@@ -52,7 +52,7 @@
assignments: assignments assignment {}
           | /* Nothing.  */        {};

-assignment: "identifier" ":=" exp { driver.variables[*$1] = $3; };
+assignment: "identifier" ":=" exp { driver.variables[*$1] = $3; delete $1;
};

%left '+' '-';
%left '*' '/';
@@ -60,7 +60,7 @@
   | exp '-' exp   { $$ = $1 - $3; }
   | exp '*' exp   { $$ = $1 * $3; }
   | exp '/' exp   { $$ = $1 / $3; }
-   | "identifier"  { $$ = driver.variables[*$1]; }
+   | "identifier"  { $$ = driver.variables[*$1]; delete $1; }
   | "number"      { $$ = $1; };
%%
#line 7568 "../../doc/bison.texinfo"


reply via email to

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