From ce1b012278c1cb5889e026abb950b5c51f8fa9dc Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Thu, 12 Feb 2009 13:38:01 +0000
Subject: [PATCH] trunk preprocessor: fixed a memory management bug related to
 the filename being parsed

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2412 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 DynareBison.yy           | 4 ++--
 DynareFlex.ll            | 4 +---
 ParsingDriver.cc         | 6 ------
 include/ParsingDriver.hh | 4 ++++
 4 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/DynareBison.yy b/DynareBison.yy
index 9ba11294..be5e33a1 100644
--- a/DynareBison.yy
+++ b/DynareBison.yy
@@ -55,8 +55,8 @@ class ParsingDriver;
 %locations
 %initial-action
 {
-  // Initialize the location filenames to NULL
-  @$.begin.filename = @$.end.filename = NULL;
+  // Initialize the locations' filenames to the filename maintained by the lexer
+  @$.begin.filename = @$.end.filename = &(driver.lexer->filename);
 }
 
 %debug
diff --git a/DynareFlex.ll b/DynareFlex.ll
index ec2b2769..8924d796 100644
--- a/DynareFlex.ll
+++ b/DynareFlex.ll
@@ -73,9 +73,7 @@ int sigma_e = 0;
  /* Rules for matching $line directives */
 <*>^@#line\ \"  { line_caller = YYSTATE; BEGIN(LINE1); }
 <LINE1>[^\"]*   {
-                  if (yylloc->begin.filename)
-                    delete yylloc->begin.filename;
-                  yylloc->begin.filename = yylloc->end.filename = new string(yytext);
+                  filename = string(yytext);
                   BEGIN(LINE2);
                 }
 <LINE2>\"       BEGIN(LINE3);
diff --git a/ParsingDriver.cc b/ParsingDriver.cc
index d9381a77..06b87379 100644
--- a/ParsingDriver.cc
+++ b/ParsingDriver.cc
@@ -72,12 +72,6 @@ ParsingDriver::parse(istream &in, bool debug)
 
   delete lexer;
 
-  /* Deleting filename in DynareFlex::yyterminate() is prematurate,
-     because if there is an unexpected end of file, the call to
-     ParsingDriver::error() needs filename */
-  /*if (location.begin.filename)
-    delete location.begin.filename;*/
-
   return mod_file;
 }
 
diff --git a/include/ParsingDriver.hh b/include/ParsingDriver.hh
index 97f790c4..a752a867 100644
--- a/include/ParsingDriver.hh
+++ b/include/ParsingDriver.hh
@@ -60,6 +60,10 @@ public:
   Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval,
                                  Dynare::parser::location_type *yylloc,
                                  ParsingDriver &driver);
+
+  //! The filename being parsed
+  /*! The bison parser locations (begin and end) contain a pointer to that string */
+  string filename;
 };
 
 //! Drives the scanning and parsing of the .mod file, and constructs its abstract representation
-- 
GitLab