changeset 11258:795c97ace02c

eliminate some possible memory leaks
author John W. Eaton <jwe@octave.org>
date Wed, 17 Nov 2010 02:40:43 -0500
parents 8d4c57258523
children fe11e2b9d48a
files src/ChangeLog src/input.cc src/oct-parse.yy src/toplev.cc
diffstat 4 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2010-11-17  John W. Eaton  <jwe@octave.org>
+
+	* oct-parse.yy (parse_fcn_file): Protect and set global_command
+	to 0 before calling yyparse.
+	* toplev.cc (main_loop): Likewise.
+
+	* oct-parse.yy (eval_string): Set global_command to 0 after
+	protecting it and before calling yyparse.
+	* input.cc (get_debug_input): Likewise.
+
 2010-11-14  Michael Goffioul  <michael.goffioul@gmail.com>
 
 	* graphics.h.in (graphics_object::get_ancestor): New method.
--- a/src/input.cc
+++ b/src/input.cc
@@ -737,6 +737,8 @@
           // Save current value of global_command.
           frame.protect_var (global_command);
 
+          global_command = 0;
+
           // Do this with an unwind-protect cleanup function so that the
           // forced variables will be unmarked in the event of an interrupt.
           symbol_table::scope_id scope = symbol_table::top_scope ();
--- a/src/oct-parse.yy
+++ b/src/oct-parse.yy
@@ -546,9 +546,7 @@
                     YYACCEPT;
                   }
                 | function_file
-                  {
-                    YYACCEPT;
-                  }
+                  { YYACCEPT; }
                 | simple_list parse_error
                   { ABORT_PARSE; }
                 | parse_error
@@ -3576,8 +3574,14 @@
 
           lexer_flags.parsing_class_method = ! dispatch_type.empty ();
 
+          frame.protect_var (global_command);
+
+          global_command = 0;
+
           int status = yyparse ();
 
+          delete global_command;
+
           fcn_ptr = primary_fcn_ptr;
 
           if (reading_fcn_file && endfunction_found && max_function_depth > 1)
@@ -4318,6 +4322,8 @@
 
       frame.protect_var (global_command);
 
+      global_command = 0;
+
       // Do this with an unwind-protect cleanup function so that the
       // forced variables will be unmarked in the event of an
       // interrupt.
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -560,6 +560,10 @@
           symbol_table::scope_id scope = symbol_table::top_scope ();
           frame.add_fcn (symbol_table::unmark_forced_variables, scope);
 
+          frame.protect_var (global_command);
+
+          global_command = 0;
+
           // This is the same as yyparse in parse.y.
           retval = octave_parse ();