perf tools: Avoid double free in read_event_file()
authorSanskriti Sharma <sansharm@redhat.com>
Tue, 2 Oct 2018 14:29:13 +0000 (10:29 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Oct 2018 17:23:46 +0000 (14:23 -0300)
The temporary 'buf' buffer allocated in read_event_file() may be freed
twice.  Move the free() call to the common function exit point.

Fixes the following coverity complaints:

  Error: USE_AFTER_FREE (CWE-825):
  tools/perf/util/trace-event-read.c:309: double_free: Calling "free"
  frees pointer "buf" which has already been freed.

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-5-git-send-email-sansharm@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/trace-event-read.c

index b98ee2a2eb445eccac7d3c753f77a38eb6e07128..a278e1eee5f5d1eb37ca04013e19c805cb57d1d1 100644 (file)
@@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char *sys,
        }
 
        ret = do_read(buf, size);
-       if (ret < 0) {
-               free(buf);
+       if (ret < 0)
                goto out;
-       }
 
        ret = parse_event_file(pevent, buf, size, sys);
        if (ret < 0)