Mercurial > hg > octave-lyh
comparison 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 |
comparison
equal
deleted
inserted
replaced
13969:3b5afcec526b | 13970:c93b953f7d54 |
---|---|
3563 | 3563 |
3564 global_command = 0; | 3564 global_command = 0; |
3565 | 3565 |
3566 int status = yyparse (); | 3566 int status = yyparse (); |
3567 | 3567 |
3568 delete global_command; | 3568 // Use an unwind-protect cleanup function so that the |
3569 // global_command list will be deleted in the event of an | |
3570 // interrupt. | |
3571 | |
3572 frame.add_fcn (cleanup_statement_list, &global_command); | |
3569 | 3573 |
3570 fcn_ptr = primary_fcn_ptr; | 3574 fcn_ptr = primary_fcn_ptr; |
3571 | 3575 |
3572 if (status != 0) | 3576 if (status != 0) |
3573 error ("parse error while reading %s file %s", | 3577 error ("parse error while reading %s file %s", |
4343 | 4347 |
4344 if (parse_status == 0) | 4348 if (parse_status == 0) |
4345 { | 4349 { |
4346 if (command_list) | 4350 if (command_list) |
4347 { | 4351 { |
4352 unwind_protect inner_frame; | |
4353 | |
4354 // Use an unwind-protect cleanup function so that the | |
4355 // global_command list will be deleted in the event of an | |
4356 // interrupt. | |
4357 | |
4358 inner_frame.add_fcn (cleanup_statement_list, &command_list); | |
4359 | |
4348 tree_statement *stmt = 0; | 4360 tree_statement *stmt = 0; |
4349 | 4361 |
4350 if (command_list->length () == 1 | 4362 if (command_list->length () == 1 |
4351 && (stmt = command_list->front ()) | 4363 && (stmt = command_list->front ()) |
4352 && stmt->is_expression ()) | 4364 && stmt->is_expression ()) |
4378 } | 4390 } |
4379 else if (nargout == 0) | 4391 else if (nargout == 0) |
4380 command_list->accept (*current_evaluator); | 4392 command_list->accept (*current_evaluator); |
4381 else | 4393 else |
4382 error ("eval: invalid use of statement list"); | 4394 error ("eval: invalid use of statement list"); |
4383 | |
4384 delete command_list; | |
4385 | |
4386 command_list = 0; | |
4387 | 4395 |
4388 if (error_state | 4396 if (error_state |
4389 || tree_return_command::returning | 4397 || tree_return_command::returning |
4390 || tree_break_command::breaking | 4398 || tree_break_command::breaking |
4391 || tree_continue_command::continuing) | 4399 || tree_continue_command::continuing) |
4424 error ("eval: expecting std::string argument"); | 4432 error ("eval: expecting std::string argument"); |
4425 return octave_value (-1); | 4433 return octave_value (-1); |
4426 } | 4434 } |
4427 | 4435 |
4428 return eval_string (s, silent, parse_status, nargout); | 4436 return eval_string (s, silent, parse_status, nargout); |
4437 } | |
4438 | |
4439 void | |
4440 cleanup_statement_list (tree_statement_list **lst) | |
4441 { | |
4442 if (*lst) | |
4443 { | |
4444 delete *lst; | |
4445 *lst = 0; | |
4446 } | |
4429 } | 4447 } |
4430 | 4448 |
4431 DEFUN (eval, args, nargout, | 4449 DEFUN (eval, args, nargout, |
4432 "-*- texinfo -*-\n\ | 4450 "-*- texinfo -*-\n\ |
4433 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\ | 4451 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\ |