Skip to contentSkip to conversation

perf tools: Fix __machine__findnew_thread() error path

PATCH In review Namhyung Kim 3 participants 3 messages Jan 9, 2015 – Jan 17, 2015 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf tools: Fix __machine__findnew_thread() error path

When thread__init_map_groups() fails, a new thread should be removed from the rbtree since it's gonna be freed. Also update last match cache only if the function succeeded.

---
 tools/perf/util/machine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +3 -1
index 94de3e48b490..1bca3a9f2b16 100644
@@ -389,7 +389,6 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
 	if (th != NULL) {
 		rb_link_node(&th->rb_node, parent, p);
 		rb_insert_color(&th->rb_node, &machine->threads);
-		machine->last_match = th;
 
 		/*
 		 * We have to initialize map_groups separately
@@ -400,9 +399,12 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
 		 * leader and that would screwed the rb tree.
 		 */
 		if (thread__init_map_groups(th, machine)) {
+			rb_erase(&th->rb_node, &machine->threads);
 			thread__delete(th);
 			return NULL;
 		}
+
+		machine->last_match = th;
 	}
 
 	return th;
Signature · 1 line
2.2.1
#2 lore raw

[tip:perf/urgent] perf machine: Fix __machine__findnew_thread() error path

In reply to Namhyung Kim
perf machine: Fix __machine__findnew_thread() error path
Commit-ID:  260d819e3abdbdaa2b88fb983d1314f1b263f9e2
Gitweb:     http://git.kernel.org/tip/260d819e3abdbdaa2b88fb983d1314f1b263f9e2
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 9 Jan 2015 09:38:12 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 16 Jan 2015 17:49:28 -0300

perf machine: Fix __machine__findnew_thread() error path

When thread__init_map_groups() fails, a new thread should be removed from the rbtree since it's gonna be freed. Also update last match cache only if the function succeeded.

---
 tools/perf/util/machine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/machine.c +3 -1
index 94de3e4..1bca3a9 100644
@@ -389,7 +389,6 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
 	if (th != NULL) {
 		rb_link_node(&th->rb_node, parent, p);
 		rb_insert_color(&th->rb_node, &machine->threads);
-		machine->last_match = th;
 
 		/*
 		 * We have to initialize map_groups separately
@@ -400,9 +399,12 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
 		 * leader and that would screwed the rb tree.
 		 */
 		if (thread__init_map_groups(th, machine)) {
+			rb_erase(&th->rb_node, &machine->threads);
 			thread__delete(th);
 			return NULL;
 		}
+
+		machine->last_match = th;
 	}
 
 	return th;