X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=dispose_cmd.c;h=c624605b5080a5ee144fe2747d72b7a3f5a59139;hb=84c617ecf0f06d4df1c3951504bb0d668c990e58;hp=4bf2c04295b32a095a7310ee9c64e2c033ae3d6d;hpb=cce855bc5b117cb7ae70064131120687bc69fac0;p=thirdparty%2Fbash.git diff --git a/dispose_cmd.c b/dispose_cmd.c index 4bf2c0429..c624605b5 100644 --- a/dispose_cmd.c +++ b/dispose_cmd.c @@ -1,22 +1,22 @@ /* dispose_command.c -- dispose of a COMMAND structure. */ -/* Copyright (C) 1987,1991 Free Software Foundation, Inc. +/* Copyright (C) 1987-2009 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 1, or (at your option) - any later version. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - Bash is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with Bash; see the file COPYING. If not, write to the Free - Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with Bash. If not, see . +*/ #include "config.h" @@ -29,6 +29,8 @@ #include "bashansi.h" #include "shell.h" +extern sh_obj_cache_t wdcache, wlcache; + /* Dispose of the command structure passed. */ void dispose_command (command) @@ -61,6 +63,21 @@ dispose_command (command) break; } +#if defined (ARITH_FOR_COMMAND) + case cm_arith_for: + { + register ARITH_FOR_COM *c; + + c = command->value.ArithFor; + dispose_words (c->init); + dispose_words (c->test); + dispose_words (c->step); + dispose_command (c->action); + free (c); + break; + } +#endif /* ARITH_FOR_COMMAND */ + case cm_group: { dispose_command (command->value.Group->command); @@ -68,6 +85,21 @@ dispose_command (command) break; } + case cm_subshell: + { + dispose_command (command->value.Subshell->command); + free (command->value.Subshell); + break; + } + + case cm_coproc: + { + free (command->value.Coproc->name); + dispose_command (command->value.Coproc->command); + free (command->value.Coproc); + break; + } + case cm_case: { register CASE_COM *c; @@ -162,14 +194,12 @@ dispose_command (command) register FUNCTION_DEF *c; c = command->value.Function_def; - dispose_word (c->name); - dispose_command (c->command); - free (c); + dispose_function_def (c); break; } default: - programming_error ("dispose_command: bad command type `%d'", command->type); + command_error ("dispose_command", CMDERR_BADTYPE, command->type, 0); break; } free (command); @@ -194,13 +224,39 @@ dispose_cond_node (cond) } #endif /* COND_COMMAND */ +void +dispose_function_def_contents (c) + FUNCTION_DEF *c; +{ + dispose_word (c->name); + dispose_command (c->command); + FREE (c->source_file); +} + +void +dispose_function_def (c) + FUNCTION_DEF *c; +{ + dispose_function_def_contents (c); + free (c); +} + /* How to free a WORD_DESC. */ void dispose_word (w) WORD_DESC *w; { FREE (w->word); - free (w); + ocache_free (wdcache, WORD_DESC, w); +} + +/* Free a WORD_DESC, but not the word contained within. */ +void +dispose_word_desc (w) + WORD_DESC *w; +{ + w->word = 0; + ocache_free (wdcache, WORD_DESC, w); } /* How to get rid of a linked list of words. A WORD_LIST. */ @@ -215,7 +271,11 @@ dispose_words (list) t = list; list = list->next; dispose_word (t->word); +#if 0 free (t); +#else + ocache_free (wlcache, WORD_LIST, t); +#endif } } @@ -249,21 +309,29 @@ dispose_redirects (list) { t = list; list = list->next; + + if (t->rflags & REDIR_VARASSIGN) + dispose_word (t->redirector.filename); + switch (t->instruction) { case r_reading_until: case r_deblank_reading_until: free (t->here_doc_eof); /*FALLTHROUGH*/ + case r_reading_string: case r_output_direction: case r_input_direction: case r_inputa_direction: case r_appending_to: case r_err_and_out: + case r_append_err_and_out: case r_input_output: case r_output_force: case r_duplicating_input_word: case r_duplicating_output_word: + case r_move_input_word: + case r_move_output_word: dispose_word (t->redirectee.filename); /* FALLTHROUGH */ default: