perf tools: Free 'printk' string in parse_ftrace_printk()
authorSanskriti Sharma <sansharm@redhat.com>
Tue, 2 Oct 2018 14:29:12 +0000 (10:29 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Oct 2018 17:23:45 +0000 (14:23 -0300)
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 <sansharm@redhat.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Link: http://lkml.kernel.org/r/1538490554-8161-4-git-send-email-sansharm@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/trace-event-parse.c

index a4d7de1c96d1eefce6a31896a29d5740d50ce5e6..02f97f5dd588354276e20e594d23cb6a8d251b7f 100644 (file)
@@ -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);
        }
 }