From: Sanskriti Sharma Date: Tue, 2 Oct 2018 14:29:12 +0000 (-0400) Subject: perf tools: Free 'printk' string in parse_ftrace_printk() X-Git-Tag: v5.15~7796^2~5^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c8a182e5a73e01afd11742a2ab887bf338fdafd;p=platform%2Fkernel%2Flinux-starfive.git perf tools: Free 'printk' string in parse_ftrace_printk() parse_ftrace_printk() tokenizes and parses a line, calling strdup() each iteration. Add code to free this temporary format string duplicate. Fixes the following coverity complaints: Error: RESOURCE_LEAK (CWE-772): tools/perf/util/trace-event-parse.c:158: overwrite_var: Overwriting "printk" in "printk = strdup(fmt + 1)" leaks the storage that "printk" points to. tools/perf/util/trace-event-parse.c:162: leaked_storage: Variable "printk" going out of scope leaks the storage it points to. Signed-off-by: Sanskriti Sharma Reviewed-by: Jiri Olsa Cc: Joe Lawrence Link: http://lkml.kernel.org/r/1538490554-8161-4-git-send-email-sansharm@redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index a4d7de1..02f97f5 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c @@ -158,6 +158,7 @@ void parse_ftrace_printk(struct tep_handle *pevent, printk = strdup(fmt+1); line = strtok_r(NULL, "\n", &next); tep_register_print_string(pevent, printk, addr); + free(printk); } }