From ac522cd7499a058e3df55fc9219fb1ff92798391 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 15 Sep 2018 15:30:00 +0200 Subject: [PATCH] Fix potential memory leak, found by Coverity Scan Signed-off-by: Joachim Nilsson --- src/complete.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/complete.c b/src/complete.c index 1b05384..d6b8a4b 100644 --- a/src/complete.c +++ b/src/complete.c @@ -362,17 +362,20 @@ static char *complete(char *token, int *match) if (!rl_attempted_completion_over && !words) words = rl_completion_matches(word, NULL); - if (words && words[0]) { + if (words) { int i = 0; free(word); - word = strdup(words[0] + len); + word = NULL; + if (words[0]) + word = strdup(words[0] + len); while (words[i]) free(words[i++]); free(words); - return word; + if (word) + return word; } fallback: