diff options
| author | Chet Ramey <chet.ramey@case.edu> | 2021-07-12 11:09:44 -0400 |
|---|---|---|
| committer | Chet Ramey <chet.ramey@case.edu> | 2021-07-12 11:09:44 -0400 |
| commit | 9e3495c9e9e1861edc9ff1da2ad96a2ce7714ad3 (patch) | |
| tree | 80ca0563b8f8f8d2682a0de4adc5d61bb1273b41 | |
| parent | 5a0e5b7b2862394cefccb919cddabf24f0ab4730 (diff) | |
| download | bash-9e3495c9.tar.gz | |
readline: free undo list associated with the saved history line when traversing history
| -rw-r--r-- | CWRU/CWRU.chlog | 17 | ||||
| -rw-r--r-- | lib/readline/bind.c | 3 | ||||
| -rw-r--r-- | lib/readline/misc.c | 13 | ||||
| -rw-r--r-- | lib/readline/search.c | 3 | ||||
| -rw-r--r-- | parse.y | 3 | ||||
| -rwxr-xr-x | tests/RUN-ONE-TEST | 2 |
6 files changed, 33 insertions, 8 deletions
diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index ee168b9..047a146 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -10696,3 +10696,20 @@ support/Makefile.in {,builtins}/Makefile.in, lib/{sh,readline,malloc,glob}/Makefile.in - use STYLE_CFLAGS so specifying CFLAGS=-g to make doesn't clutter the output with warnings about parens and format strings + + 7/9 + --- +lib/readline/search.c + - make_history_line_current: call _rl_free_saved_history_line to clean + up _rl_saved_line_from_history and get all the code that frees it + into one place + +lib/readline/misc.c + - _rl_free_saved_history_line: if rl_undo_list points to the data + member of _rl_saved_line_from_history, set it to NULL to avoid having + it point to freed memory, since the next thing we do now is to free + the undo list the data member points to + - _rl_start_using_history: call _rl_free_saved_history_line instead of + calling _rl_free_history_entry directly. Fixes memory leak reported + by Trung Dam <trungdam@yahoo.com> + diff --git a/lib/readline/bind.c b/lib/readline/bind.c index f1456d6..4f4539d 100644 --- a/lib/readline/bind.c +++ b/lib/readline/bind.c @@ -934,7 +934,6 @@ rl_trim_arg_from_keyseq (const char *keyseq, size_t len, Keymap map) if (i + 1 == len) return -1; - map = map0; parsing_digits = 1; /* This logic should be identical to rl_digit_loop */ @@ -949,6 +948,8 @@ rl_trim_arg_from_keyseq (const char *keyseq, size_t len, Keymap map) { parsing_digits = 2; } + + map = map0; j = i + 1; } } diff --git a/lib/readline/misc.c b/lib/readline/misc.c index 23f2ad5..e903d92 100644 --- a/lib/readline/misc.c +++ b/lib/readline/misc.c @@ -306,8 +306,7 @@ _rl_start_using_history (void) { using_history (); if (_rl_saved_line_for_history) - _rl_free_history_entry (_rl_saved_line_for_history); - + _rl_free_saved_history_line (); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; } @@ -352,6 +351,8 @@ rl_maybe_unsave_line (void) list from a history entry, as in rl_replace_from_history() below. */ rl_replace_line (_rl_saved_line_for_history->line, 0); rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data; + + /* Doesn't free `data'. */ _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; rl_point = rl_end; /* rl_replace_line sets rl_end */ @@ -381,6 +382,14 @@ _rl_free_saved_history_line (void) { if (_rl_saved_line_for_history) { + if (rl_undo_list && rl_undo_list == (UNDO_LIST *)_rl_saved_line_for_history->data) + rl_undo_list = 0; + /* Have to free this separately because _rl_free_history entry can't: + it doesn't know whether or not this has application data. Only the + callers that know this is _rl_saved_line_for_history can know that + it's an undo list. */ + if (_rl_saved_line_for_history->data) + _rl_free_undo_list ((UNDO_LIST *)_rl_saved_line_for_history->data); _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; } diff --git a/lib/readline/search.c b/lib/readline/search.c index 6cfe97d..0b70d54 100644 --- a/lib/readline/search.c +++ b/lib/readline/search.c @@ -96,8 +96,7 @@ make_history_line_current (HIST_ENTRY *entry) #endif if (_rl_saved_line_for_history) - _rl_free_history_entry (_rl_saved_line_for_history); - _rl_saved_line_for_history = (HIST_ENTRY *)NULL; + _rl_free_saved_history_line (); } /* Search the history list for STRING starting at absolute history position @@ -989,8 +989,7 @@ comsub: DOLPAREN compound_list ')' { $$ = $2; } - | - DOLPAREN newline_list ')' + | DOLPAREN newline_list ')' { $$ = (COMMAND *)NULL; } diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index c8bef8d..0b06381 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 |
