diff options
author | Franck Bui-Huu <fbuihuu@gmail.com> | 2012-05-25 09:21:49 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-25 10:40:59 -0400 |
commit | e8cdd947776300f962d5b699c34087af45a8aea7 (patch) | |
tree | 819f25aa3ca86310ae96a3debe31cfb09deff19f /tools/perf | |
parent | a83eb3ea97efbc891b2f67e91329638cd4e21622 (diff) |
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')
-rw-r--r-- | tools/perf/util/thread_map.c | 21 |
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) | |||
188 | nt = realloc(threads, (sizeof(*threads) + | 188 | nt = realloc(threads, (sizeof(*threads) + |
189 | sizeof(pid_t) * total_tasks)); | 189 | sizeof(pid_t) * total_tasks)); |
190 | if (nt == NULL) | 190 | if (nt == NULL) |
191 | goto out_free_threads; | 191 | goto out_free_namelist; |
192 | 192 | ||
193 | threads = nt; | 193 | threads = nt; |
194 | 194 | ||
195 | if (threads) { | 195 | for (i = 0; i < items; i++) { |
196 | for (i = 0; i < items; i++) | 196 | threads->map[j++] = atoi(namelist[i]->d_name); |
197 | threads->map[j++] = atoi(namelist[i]->d_name); | ||
198 | threads->nr = total_tasks; | ||
199 | } | ||
200 | |||
201 | for (i = 0; i < items; i++) | ||
202 | free(namelist[i]); | 197 | free(namelist[i]); |
198 | } | ||
199 | threads->nr = total_tasks; | ||
203 | free(namelist); | 200 | free(namelist); |
204 | |||
205 | if (!threads) | ||
206 | break; | ||
207 | } | 201 | } |
208 | 202 | ||
209 | out: | 203 | out: |
210 | strlist__delete(slist); | 204 | strlist__delete(slist); |
211 | return threads; | 205 | return threads; |
212 | 206 | ||
207 | out_free_namelist: | ||
208 | for (i = 0; i < items; i++) | ||
209 | free(namelist[i]); | ||
210 | free(namelist); | ||
211 | |||
213 | out_free_threads: | 212 | out_free_threads: |
214 | free(threads); | 213 | free(threads); |
215 | threads = NULL; | 214 | threads = NULL; |