perf annotate: Plug filename string leak
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 1 Aug 2016 21:49:13 +0000 (18:49 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 1 Aug 2016 21:49:13 +0000 (18:49 -0300)
If dso__build_id_filename(..., NULL, ...) returns !NULL its because it
allocated it, so, when reaching the  'if (dso__is_kcore()) test, we
already checked that and were just "fallbacking" to using
dso->long_name, but without freeing filename, thus leaking it.

Fix it by adding the dso__is_kcore() test to the 'or' group just after
it, the one containing the full fallback code, including freeing the
filename.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Fixes: ee205503f233 ("perf tools: Fix annotation with kcore")
Link: http://lkml.kernel.org/n/tip-qi4rpjq8yo6myvg99kkgt0xz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate.c

index 4982ed487e962378a01d125262164d9654414256..4024d309bb00adaa2dbdb0a6e80afa2e6a5935a9 100644 (file)
@@ -1185,9 +1185,8 @@ int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
                if (dso->has_build_id)
                        return ENOMEM;
                goto fallback;
-       } else if (dso__is_kcore(dso)) {
-               goto fallback;
-       } else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
+       } else if (dso__is_kcore(dso) ||
+                  readlink(symfs_filename, command, sizeof(command)) < 0 ||
                   strstr(command, DSO__NAME_KALLSYMS) ||
                   access(symfs_filename, R_OK)) {
                free(filename);