[gnu.bash.bug] Bash 1.04 patch: function return -- IMPORTANT

chip@ateng.ateng.com (Chip Salzenberg) (01/23/90)

Bash 1.04 has a serious bug in the handling of the "return" statement in
shell functions.  Falling off the end of a shell function automatically
cleans up local variables and redirection.  The code obviously should do
the same when the "return" statement is executed, but Bash 1.04, as
distributed, does not do so.  This patch fixes the bug.

Index: execute_cmd.c
***************
*** 741,747 ****
  			  remember_args (words->next, 1);
  			  result = execute_command (tc);
- 			  run_unwind_frame ("function_calling");
  			}
  		      return_catch_flag--;
  		      redirection_undo_list = saved_undo_list;
  		    }
--- 741,749 ----
  			  remember_args (words->next, 1);
  			  result = execute_command (tc);
  			}
+ 		      run_unwind_frame ("function_calling");
  		      return_catch_flag--;
+ 		      do_redirections (redirection_undo_list, 1, 0);
+ 		      dispose_redirects (redirection_undo_list);
  		      redirection_undo_list = saved_undo_list;
  		    }