public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] perf tools: fix thread_map__new_by_pid_str() memory leak in error path
@ 2012-05-25 13:21 Franck Bui-Huu
  2012-05-25 14:40 ` Arnaldo Carvalho de Melo
  2012-05-30  7:44 ` [tip:perf/urgent] " tip-bot for Franck Bui-Huu
  0 siblings, 2 replies; 3+ messages in thread
From: Franck Bui-Huu @ 2012-05-25 13:21 UTC (permalink / raw)
  To: acme; +Cc: dsahern, linux-kernel

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>
---
 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 84d9bd78..9b5f856 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;
-- 
1.7.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] perf tools: fix thread_map__new_by_pid_str() memory leak in error path
  2012-05-25 13:21 [PATCH 1/1] perf tools: fix thread_map__new_by_pid_str() memory leak in error path Franck Bui-Huu
@ 2012-05-25 14:40 ` Arnaldo Carvalho de Melo
  2012-05-30  7:44 ` [tip:perf/urgent] " tip-bot for Franck Bui-Huu
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-05-25 14:40 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: dsahern, linux-kernel

Em Fri, May 25, 2012 at 03:21:49PM +0200, Franck Bui-Huu escreveu:
> 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>

Thanks, applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/urgent] perf tools: fix thread_map__new_by_pid_str() memory leak in error path
  2012-05-25 13:21 [PATCH 1/1] perf tools: fix thread_map__new_by_pid_str() memory leak in error path Franck Bui-Huu
  2012-05-25 14:40 ` Arnaldo Carvalho de Melo
@ 2012-05-30  7:44 ` tip-bot for Franck Bui-Huu
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Franck Bui-Huu @ 2012-05-30  7:44 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, dsahern, fbuihuu, tglx

Commit-ID:  e8cdd947776300f962d5b699c34087af45a8aea7
Gitweb:     http://git.kernel.org/tip/e8cdd947776300f962d5b699c34087af45a8aea7
Author:     Franck Bui-Huu <fbuihuu@gmail.com>
AuthorDate: Fri, 25 May 2012 15:21:49 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 25 May 2012 11:40:59 -0300

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>
---
 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 84d9bd78..9b5f856 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;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-30  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 13:21 [PATCH 1/1] perf tools: fix thread_map__new_by_pid_str() memory leak in error path Franck Bui-Huu
2012-05-25 14:40 ` Arnaldo Carvalho de Melo
2012-05-30  7:44 ` [tip:perf/urgent] " tip-bot for Franck Bui-Huu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox