From 76a8d78dfdc9e2e7ae1498eca89ea62056ca6fae Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Sat, 3 Dec 2011 13:40:44 -0500 Subject: [PATCH] commit bash-20041202 snapshot --- CWRU/CWRU.chlog | 30 ++++++++++++++++++++++++++++++ doc/bash.1 | 23 ++++++++++++++--------- doc/bashref.texi | 21 +++++++++++++-------- doc/version.texi | 6 +++--- execute_cmd.c | 27 +++++++-------------------- lib/glob/xmbsrtowcs.c | 19 ++++++++++++------- lib/readline/misc.c | 8 ++++++-- tests/RUN-ONE-TEST | 2 +- trap.c | 5 +++++ 9 files changed, 91 insertions(+), 50 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 40b29b083..dd4bf49e6 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -10644,3 +10644,33 @@ execute_cmd.c trap.c - change reset_or_restore_signal_handlers so that the RETURN trap is not inherited by command substitution when DEBUGGER is not defined + + 11/30 + ----- +lib/readline/misc.c + - fix memory leaks in _rl_free_history_entry and rl_maybe_replace_line + caused by not freeing `timestamp' member of history entry + - make sure timestamp is initialized to NULL in rl_maybe_save_line + + 12/1 + ---- +execute_cmd.c + - fix execute_function so a function calling `return' will run the + RETURN trap, if one's defined + +doc/{bash.1,bashref.texi} + - fix description of RETURN trap in various places to indicate that it's + only inherited by shell functions if function tracing is on globally + or has been enabled for that function + - fix documentation to indicate that the DEBUG and RETURN traps are + inherited under the same conditions + +execute_cmd.c + - a function does not inherit the RETURN trap if a DEBUG trap is + currently running + + 12/2 + ---- +lib/glob/xmbsrtowcs.c + - change xmbsrtowcs to handle the one case where malloc can fail + (though it should not matter) -- don't try to free a null pointer diff --git a/doc/bash.1 b/doc/bash.1 index 29f9a3860..544b85c5a 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -6,12 +6,12 @@ .\" Case Western Reserve University .\" chet@po.CWRU.Edu .\" -.\" Last Change: Mon Nov 22 11:06:21 EST 2004 +.\" Last Change: Wed Dec 1 15:39:20 EST 2004 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2004 Nov 22" "GNU Bash-3.1-devel" +.TH BASH 1 "2004 Dec 1" "GNU Bash-3.1-devel" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -3320,19 +3320,21 @@ environment are identical between a function and its caller with the exception that the .SM .B DEBUG -trap (see the description of the +and +.B RETURN +traps (see the description of the .B trap builtin under .SM .B SHELL BUILTIN COMMANDS -below) is not inherited unless the function has been given the +below) are not inherited unless the function has been given the \fBtrace\fP attribute (see the description of the .SM .B declare builtin below) or the \fB\-o functrace\fP shell option has been enabled with the \fBset\fP builtin -(in which case all functions inherit the \fBDEBUG\fP trap). +(in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps). .PP Variables local to the function may be declared with the .B local @@ -6424,7 +6426,8 @@ by subsequent assignment statements or unset. .TP .B \-t Give each \fIname\fP the \fItrace\fP attribute. -Traced functions inherit the \fBDEBUG\fP trap from the calling shell. +Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from +the calling shell. The trace attribute has no special meaning for variables. .TP .B \-x @@ -7773,9 +7776,11 @@ follows the logical chain of directories when performing commands which change the current directory. .TP 8 .B \-T -If set, any trap on \fBDEBUG\fP is inherited by shell functions, command -substitutions, and commands executed in a subshell environment. -The \fBDEBUG\fP trap is normally not inherited in such cases. +If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell +functions, command substitutions, and commands executed in a +subshell environment. +The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited +in such cases. .TP 8 .B \-\- If no arguments follow this option, then the positional parameters are diff --git a/doc/bashref.texi b/doc/bashref.texi index b1b014dbe..81dd4945f 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -1118,12 +1118,12 @@ The first element of the @env{FUNCNAME} variable is set to the name of the function while the function is executing. All other aspects of the shell execution environment are identical between a function and its caller -with the exception that the @env{DEBUG} trap -below) is not inherited unless the function has been given the +with the exception that the @env{DEBUG} and @env{RETURN} traps +are not inherited unless the function has been given the @code{trace} attribute using the @code{declare} builtin or the @code{-o functrace} option has been enabled with the @code{set} builtin, -(in which case all functions inherit the @code{DEBUG} trap). +(in which case all functions inherit the @env{DEBUG} and @env{RETURN} traps). @xref{Bourne Shell Builtins}, for the description of the @code{trap} builtin. @@ -3283,7 +3283,8 @@ by subsequent assignment statements or unset. @item -t Give each @var{name} the @code{trace} attribute. -Traced functions inherit the @code{DEBUG} trap from the calling shell. +Traced functions inherit the @code{DEBUG} and @code{RETURN} traps from +the calling shell. The trace attribute has no special meaning for variables. @item -x @@ -4126,9 +4127,11 @@ $ cd ..; pwd @end example @item -T -If set, any trap on @code{DEBUG} is inherited by shell functions, command -substitutions, and commands executed in a subshell environment. -The @code{DEBUG} trap is normally not inherited in such cases. +If set, any trap on @code{DEBUG} and @code{RETURN} are inherited by +shell functions, command substitutions, and commands executed +in a subshell environment. +The @code{DEBUG} and @code{RETURN} traps are normally not inherited +in such cases. @item -- If no arguments follow this option, then the positional parameters are @@ -7184,7 +7187,9 @@ The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a Commands specified with an @code{RETURN} trap are executed before execution resumes after a shell function or a shell script executed with @code{.} or @code{source} returns. -The @code{RETURN} trap is not inherited by shell functions. +The @code{RETURN} trap is not inherited by shell functions unless the +function has been given the @code{trace} attribute or the +@code{functrace} option has been enabled using the @code{shopt} builtin. @item The Bash @code{type} builtin is more extensive and gives more information diff --git a/doc/version.texi b/doc/version.texi index 9aef4ca7a..804df1f11 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,9 +2,9 @@ Copyright (C) 1988-2004 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Wed Nov 24 14:11:51 EST 2004 +@set LASTCHANGE Wed Dec 1 15:39:35 EST 2004 @set EDITION 3.1-devel @set VERSION 3.1-devel -@set UPDATED 24 November 2004 -@set UPDATED-MONTH November 2004 +@set UPDATED 1 December 2004 +@set UPDATED-MONTH December 2004 diff --git a/execute_cmd.c b/execute_cmd.c index 69f188558..4824175df 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -2741,35 +2741,20 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close) if (dofork) { -#if 0 - /* XXX memory leak if expand_words() error causes a jump_to_top_level */ - command_line = savestring (the_printed_command); -#endif - /* Do this now, because execute_disk_command will do it anyway in the vast majority of cases. */ maybe_make_export_env (); -#if 0 - if (make_child (command_line, async) == 0) -#else if (make_child (savestring (the_printed_command), async) == 0) -#endif { already_forked = 1; simple_command->flags |= CMD_NO_FORK; -#if 0 - subshell_environment = (pipe_in != NO_PIPE || pipe_out != NO_PIPE) - ? (SUBSHELL_PIPE|SUBSHELL_FORK) - : (SUBSHELL_ASYNC|SUBSHELL_FORK); -#else subshell_environment = SUBSHELL_FORK; if (pipe_in != NO_PIPE || pipe_out != NO_PIPE) subshell_environment |= SUBSHELL_PIPE; if (async) subshell_environment |= SUBSHELL_ASYNC; -#endif /* We need to do this before piping to handle some really pathological cases where one of the pipe file descriptors @@ -3187,7 +3172,13 @@ execute_function (var, words, flags, fds_to_close, async, subshell) restore_default_signal (ERROR_TRAP); } + /* Shell functions inherit the RETURN trap if function tracing is on + globally or on individually for this function. */ +#if 0 if (return_trap && ((trace_p (var) == 0) && function_trace_mode == 0)) +#else + if (return_trap && (signal_in_progress (DEBUG_TRAP) || ((trace_p (var) == 0) && function_trace_mode == 0))) +#endif { if (subshell == 0) { @@ -3242,14 +3233,10 @@ execute_function (var, words, flags, fds_to_close, async, subshell) if (return_val) { result = return_catch_value; -#if 0 - /* Run the RETURN trap in the function's context. XXX - have to talk - to Rocky about why his bashdb code doesn't have `return' run the - RETURN trap. */ + /* Run the RETURN trap in the function's context. */ save_current = currently_executing_command; run_return_trap (); currently_executing_command = save_current; -#endif } else { diff --git a/lib/glob/xmbsrtowcs.c b/lib/glob/xmbsrtowcs.c index f1703bccf..f8c29b915 100644 --- a/lib/glob/xmbsrtowcs.c +++ b/lib/glob/xmbsrtowcs.c @@ -1,6 +1,6 @@ /* xmbsrtowcs.c -- replacement function for mbsrtowcs */ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002-2004 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -54,7 +54,7 @@ xmbsrtowcs (dest, src, len, pstate) ps = &local_state; } - n = strlen(*src); + n = strlen (*src); if (dest == NULL) { @@ -62,19 +62,22 @@ xmbsrtowcs (dest, src, len, pstate) const char *mbs; mbstate_t psbuf; + /* It doesn't matter if malloc fails here, since mbsrtowcs should do + the right thing with a NULL first argument. */ wsbuf = (wchar_t *) malloc ((n + 1) * sizeof(wchar_t)); mbs = *src; psbuf = *ps; wclength = mbsrtowcs (wsbuf, &mbs, n, &psbuf); - free (wsbuf); + if (wsbuf) + free (wsbuf); return wclength; } for (wclength = 0; wclength < len; wclength++, dest++) { - if(mbsinit(ps)) + if (mbsinit(ps)) { if (**src == '\0') { @@ -166,10 +169,11 @@ xdupmbstowcs (destp, indicesp, src) p = src; wcnum = 0; - do { + do + { size_t mblength; /* Byte length of one multibyte character. */ - if(mbsinit (&state)) + if (mbsinit (&state)) { if (*p == '\0') { @@ -230,7 +234,8 @@ xdupmbstowcs (destp, indicesp, src) wsbuf[wcnum - 1] = wc; indices[wcnum - 1] = (char *)p; p += mblength; - } while (MB_NULLWCH (wc) == 0); + } + while (MB_NULLWCH (wc) == 0); /* Return the length of the wide character string, not including `\0'. */ *destp = wsbuf; diff --git a/lib/readline/misc.c b/lib/readline/misc.c index 403313a04..5054358d1 100644 --- a/lib/readline/misc.c +++ b/lib/readline/misc.c @@ -225,8 +225,10 @@ _rl_free_history_entry (entry) { if (entry == 0) return; - if (entry->line) - free (entry->line); + + FREE (entry->line); + FREE (entry->timestamp); + free (entry); } @@ -242,6 +244,7 @@ rl_maybe_replace_line () { temp = replace_history_entry (where_history (), rl_line_buffer, (histdata_t)rl_undo_list); free (temp->line); + FREE (temp->timestamp); free (temp); } return 0; @@ -274,6 +277,7 @@ rl_maybe_save_line () { _rl_saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); _rl_saved_line_for_history->line = savestring (rl_line_buffer); + _rl_saved_line_for_history->timestamp = (char *)NULL; _rl_saved_line_for_history->data = (char *)rl_undo_list; } diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 72ec06a2c..3efcf32d6 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/bash/bash-current +BUILD_DIR=/usr/local/build/chet/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/trap.c b/trap.c index 71dc64053..ef1d95ac4 100644 --- a/trap.c +++ b/trap.c @@ -807,6 +807,11 @@ run_return_trap () { int old_exit_value; +#if 0 + if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && (sigmodes[DEBUG_TRAP] & SIG_INPROGRESS)) + return; +#endif + if ((sigmodes[RETURN_TRAP] & SIG_TRAPPED) && ((sigmodes[RETURN_TRAP] & SIG_IGNORED) == 0) && (sigmodes[RETURN_TRAP] & SIG_INPROGRESS) == 0) { old_exit_value = last_command_exit_value; -- 2.47.3