diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-05-09 12:31:56 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-05-09 12:31:56 +0000 |
commit | 1ebd453cb284e987e38aa760f0620acbf0891c10 (patch) | |
tree | 1443e2abfa0bdba6a3df7b5b6159065e164e58aa /lib/libedit | |
parent | 88bddcd2781dfbe4fb9a5676a517a3fbaa8d01d7 (diff) |
Fix stifle_history(): Remove excessive entries, if any.
Based on a patch from Bastian Maerkisch <bmaerkisch at web dot de>,
with an additional fix for a memory leak by me.
OK czarkoff@
Diffstat (limited to 'lib/libedit')
-rw-r--r-- | lib/libedit/readline.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c index 0675b16a705..853d3c9c4c4 100644 --- a/lib/libedit/readline.c +++ b/lib/libedit/readline.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readline.c,v 1.23 2016/05/08 13:52:33 schwarze Exp $ */ +/* $OpenBSD: readline.c,v 1.24 2016/05/09 12:31:55 schwarze Exp $ */ /* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */ /*- @@ -1127,12 +1127,24 @@ void stifle_history(int max) { HistEvent ev; + HIST_ENTRY *he; + int i, len; if (h == NULL || e == NULL) rl_initialize(); - if (history(h, &ev, H_SETSIZE, max) == 0) + len = history_length; + if (history(h, &ev, H_SETSIZE, max) == 0) { max_input_history = max; + if (max < len) + history_base += len - max; + for (i = 0; i < len - max; i++) { + he = remove_history(i); + free(he->data); + free((void *)he->line); + free(he); + } + } } |