summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/thread_map.c
diff options
context:
space:
mode:
authorFranck Bui-Huu <fbuihuu@gmail.com>2012-05-25 15:21:49 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-05-25 16:40:59 +0200
commite8cdd947776300f962d5b699c34087af45a8aea7 (patch)
tree819f25aa3ca86310ae96a3debe31cfb09deff19f /tools/perf/util/thread_map.c
parentperf tools: Do not use _FORTIFY_SOURCE when DEBUG=1 is specified (diff)
downloadlinux-e8cdd947776300f962d5b699c34087af45a8aea7.tar.xz
linux-e8cdd947776300f962d5b699c34087af45a8aea7.zip
perf tools: fix thread_map__new_by_pid_str() memory leak in error path
The namelist array (including its content) was not freed if we fail to realloc a new 'threads' structure. Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com> Cc: David Ahern <dsahern@gmail.com> Link: http://lkml.kernel.org/r/1337952109-31995-1-git-send-email-fbuihuu@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/thread_map.c')
-rw-r--r--tools/perf/util/thread_map.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 84d9bd782004..9b5f856cc280 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -188,28 +188,27 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str)
nt = realloc(threads, (sizeof(*threads) +
sizeof(pid_t) * total_tasks));
if (nt == NULL)
- goto out_free_threads;
+ goto out_free_namelist;
threads = nt;
- if (threads) {
- for (i = 0; i < items; i++)
- threads->map[j++] = atoi(namelist[i]->d_name);
- threads->nr = total_tasks;
- }
-
- for (i = 0; i < items; i++)
+ for (i = 0; i < items; i++) {
+ threads->map[j++] = atoi(namelist[i]->d_name);
free(namelist[i]);
+ }
+ threads->nr = total_tasks;
free(namelist);
-
- if (!threads)
- break;
}
out:
strlist__delete(slist);
return threads;
+out_free_namelist:
+ for (i = 0; i < items; i++)
+ free(namelist[i]);
+ free(namelist);
+
out_free_threads:
free(threads);
threads = NULL;