Mercurial > hg > octave-nkf
diff src/oct-parse.yy @ 13970:c93b953f7d54
plug some memory leaks
* oct-parse.yy, parse.h (cleanup_statement_list): New function.
* toplev.cc (main_loop): Put cleanup_statement_list on the
unwind_protect stack to delete the command list created by the
parser instead of deleting it directly.
* oct-parse.yy (parse_fcn_file, eval_string): Likewise.
* input.cc (get_debug_input): Likewise.
* pt-loop.cc (tree_simple_for_command::~tree_simple_for_command,
tree_complex_for_command::~tree_complex_for_command):
Also delete lhs expression.
* pt-idx.cc (tree_index_expression::~tree_index_expression):
Also delete contents of dyn_field list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 01 Dec 2011 04:26:46 -0500 |
parents | e48529b3dbd4 |
children | 5aba9fa234cf |
line wrap: on
line diff
--- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -3565,7 +3565,11 @@ int status = yyparse (); - delete global_command; + // Use an unwind-protect cleanup function so that the + // global_command list will be deleted in the event of an + // interrupt. + + frame.add_fcn (cleanup_statement_list, &global_command); fcn_ptr = primary_fcn_ptr; @@ -4345,6 +4349,14 @@ { if (command_list) { + unwind_protect inner_frame; + + // Use an unwind-protect cleanup function so that the + // global_command list will be deleted in the event of an + // interrupt. + + inner_frame.add_fcn (cleanup_statement_list, &command_list); + tree_statement *stmt = 0; if (command_list->length () == 1 @@ -4381,10 +4393,6 @@ else error ("eval: invalid use of statement list"); - delete command_list; - - command_list = 0; - if (error_state || tree_return_command::returning || tree_break_command::breaking @@ -4428,6 +4436,16 @@ return eval_string (s, silent, parse_status, nargout); } +void +cleanup_statement_list (tree_statement_list **lst) +{ + if (*lst) + { + delete *lst; + *lst = 0; + } +} + DEFUN (eval, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\