[PATCH perf/core 08/22] perf: Make thread uses refcnt for debug

Masami Hiramatsu
2015-12-09T02:19:01Z

Make 'thread' object to use refcnt interface for debug.
This can find refcnt related memory leaks.
E.g.

----
# ./perf top --stdio
^q
REFCNT: BUG: Unreclaimed objects found.
REFCNT: Total 3525 objects are not reclaimed.
"map" leaks 3285 objects
"dso" leaks 225 objects
"thread" leaks 8 objects
"map_groups" leaks 7 objects
To see all backtraces, rerun with -v option
----

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/util/thread.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0a9ae80..392fc32 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -53,7 +53,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
goto err_thread;

list_add(&comm->list, &thread->comm_list);
- atomic_set(&thread->refcnt, 0);
+ refcnt__init(thread, refcnt, 0);
RB_CLEAR_NODE(&thread->rb_node);
}

@@ -81,6 +81,7 @@ void thread__delete(struct thread *thread)
comm__free(comm);
}
unwind__finish_access(thread);
+ refcnt__exit(thread, refcnt);

free(thread);
}
@@ -88,13 +89,13 @@ void thread__delete(struct thread *thread)
struct thread *thread__get(struct thread *thread)
{
if (thread)
- atomic_inc(&thread->refcnt);
+ refcnt__get(thread, refcnt);
return thread;
}

void thread__put(struct thread *thread)
{
- if (thread && atomic_dec_and_test(&thread->refcnt)) {
+ if (thread && refcnt__put(thread, refcnt)) {
list_del_init(&thread->node);
thread__delete(thread);
}