changeset 13973:2c664266e9d0

clean up parser memory on exit * lex.h, lex.ll (clear_all_buffers, cleanup_parser): New functions. * toplev.cc (clean_up_and_exit): Call cleanup_parser here.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Dec 2011 03:51:37 -0500
parents 09432c6f23e7
children f5bd61eb032f
files src/lex.h src/lex.ll src/toplev.cc
diffstat 3 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lex.h	Thu Dec 01 11:09:50 2011 -0800
+++ b/src/lex.h	Fri Dec 02 03:51:37 2011 -0500
@@ -43,6 +43,10 @@
 // Delete a buffer.
 extern OCTINTERP_API void delete_buffer (YY_BUFFER_STATE buf);
 
+extern OCTINTERP_API void clear_all_buffers (void);
+
+extern OCTINTERP_API void cleanup_parser (void);
+
 // Is the given string a keyword?
 extern bool is_keyword (const std::string& s);
 
--- a/src/lex.ll	Thu Dec 01 11:09:50 2011 -0800
+++ b/src/lex.ll	Fri Dec 02 03:51:37 2011 -0500
@@ -1416,6 +1416,22 @@
   yy_delete_buffer (buf);
 }
 
+// Delete all buffers from the stack.
+void
+clear_all_buffers (void)
+{                 
+  while (current_buffer ())
+    octave_pop_buffer_state ();
+}
+
+void
+cleanup_parser (void)
+{
+  reset_parser ();
+
+  clear_all_buffers ();
+}
+
 // Restore a buffer (for unwind-prot).
 
 void
--- a/src/toplev.cc	Thu Dec 01 11:09:50 2011 -0800
+++ b/src/toplev.cc	Fri Dec 02 03:51:37 2011 -0500
@@ -676,6 +676,8 @@
   // Clean up symbol table.
   SAFE_CALL (symbol_table::cleanup, ());
 
+  SAFE_CALL (cleanup_parser, ());
+
   SAFE_CALL (sysdep_cleanup, ())
 
   if (octave_exit)