From 21f243c760596afb5c772473ce24e8c6646dfbd7 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 14 Jun 2016 11:58:21 +0200 Subject: [PATCH] lldpcli: fix memory leak with use of readline The lines returned by readline() should be freed. --- src/client/lldpcli.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index 1079069e..e534343c 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -254,7 +254,7 @@ readline(const char *p) fflush(stderr); if (fgets(line, sizeof(line) - 2, stdin) == NULL) return NULL; - return line; + return strdup(line); } #endif @@ -579,14 +579,16 @@ main(int argc, char *argv[]) rl_bind_key('?', cmd_help); rl_bind_key('\t', cmd_complete); #endif - const char *line; + char *line = NULL; do { if ((line = readline(prompt()))) { int n = parse_and_exec(conn, fmt, line); - (void)n; + if (n != 0) { #ifdef HAVE_READLINE_HISTORY - if (n != 0) add_history(line); + add_history(line); #endif + } + free(line); } } while (!must_exit && line != NULL); rc = EXIT_SUCCESS; -- 2.39.5