summaryrefslogtreecommitdiff
path: root/lib/readline/histexpand.c
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2011-12-07 09:11:26 -0500
committerChet Ramey <chet.ramey@case.edu>2011-12-07 09:11:26 -0500
commitcb603128ea23bd1fcca8e3c13296afa83c16fe45 (patch)
treebeade54a7b707496d77aac7e4b00c405a691ac60 /lib/readline/histexpand.c
parent29f3080f708b3d0a9f6a464a3d8be4d0938da7ae (diff)
downloadbash-cb603128ea23bd1fcca8e3c13296afa83c16fe45.tar.gz
commit bash-20070823 snapshot
Diffstat (limited to 'lib/readline/histexpand.c')
-rw-r--r--lib/readline/histexpand.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/readline/histexpand.c b/lib/readline/histexpand.c
index c07d769b..4df87d47 100644
--- a/lib/readline/histexpand.c
+++ b/lib/readline/histexpand.c
@@ -64,10 +64,11 @@ static int subst_lhs_len;
static int subst_rhs_len;
static char *get_history_word_specifier PARAMS((char *, char *, int *));
-static char *history_find_word PARAMS((char *, int));
static int history_tokenize_word PARAMS((const char *, int));
static char **history_tokenize_internal PARAMS((const char *, int, int *));
static char *history_substring PARAMS((const char *, int, int));
+static void freewords PARAMS((char **, int));
+static char *history_find_word PARAMS((char *, int));
static char *quote_breaks PARAMS((char *));
@@ -1570,6 +1571,18 @@ history_tokenize (string)
return (history_tokenize_internal (string, -1, (int *)NULL));
}
+/* Free members of WORDS from START to an empty string */
+static void
+freewords (words, start)
+ char **words;
+ int start;
+{
+ register int i;
+
+ for (i = start; words[i]; i++)
+ free (words[i]);
+}
+
/* Find and return the word which contains the character at index IND
in the history line LINE. Used to save the word matched by the
last history !?string? search. */
@@ -1584,14 +1597,15 @@ history_find_word (line, ind)
words = history_tokenize_internal (line, ind, &wind);
if (wind == -1 || words == 0)
{
+ if (words)
+ freewords (words, 0);
FREE (words);
return ((char *)NULL);
}
s = words[wind];
for (i = 0; i < wind; i++)
free (words[i]);
- for (i = wind + 1; words[i]; i++)
- free (words[i]);
+ freewords (words, wind + 1);
free (words);
return s;
}