perf session: Invalidate last_match when removing threads from rb_tree
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 2 Aug 2010 21:59:28 +0000 (18:59 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 2 Aug 2010 22:01:09 +0000 (19:01 -0300)
If we receive two PERF_RECORD_EXIT for the same thread, we can end up
reusing session->last_match and trying to remove the thread twice from
the rb_tree, causing a segfault, so invalidade last_match in
perf_session__remove_thread.

Receiving two PERF_RECORD_EXIT for the same thread is a bug, but its a
harmless one if we make the tool more robust, like this patch does.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/session.c

index 5d2fd52fe7b5167af4f7c63806f2d9d72ec4ecee..fa9d652c2dc3c07182028d4a196293333be75d78 100644 (file)
@@ -166,6 +166,7 @@ void perf_session__delete(struct perf_session *self)
 
 void perf_session__remove_thread(struct perf_session *self, struct thread *th)
 {
+       self->last_match = NULL;
        rb_erase(&th->rb_node, &self->threads);
        /*
         * We may have references to this thread, for instance in some hist_entry