From: Vincent Bernat Date: Tue, 14 Jun 2016 09:58:21 +0000 (+0200) Subject: lldpcli: fix memory leak with use of readline X-Git-Tag: 0.9.4~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21f243c760596afb5c772473ce24e8c6646dfbd7;p=thirdparty%2Flldpd.git lldpcli: fix memory leak with use of readline The lines returned by readline() should be freed. --- 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;