Skip to contentSkip to conversation

perf trace: Fix some leaks of struct thread

PATCH Superseded Namhyung Kim 3 participants 4 messages Mar 31, 2025 – Apr 3, 2025 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf trace: Fix some leaks of struct thread

I've found some leaks from 'perf trace -a'. It seems there are more leaks but this is what I can find for now.

---
 tools/perf/builtin-trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +3 -1
index 3d0c0076884d34cb..10cd99888a9a11b5 100644
@@ -2835,7 +2835,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
 	e_machine = thread__e_machine(thread, trace->host);
 	sc = trace__syscall_info(trace, evsel, e_machine, id);
 	if (sc == NULL)
-		return -1;
+		goto out_put;
 	ttrace = thread__trace(thread, trace);
 	/*
 	 * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
@@ -4123,8 +4123,10 @@ static int trace__set_filter_loop_pids(struct trace *trace)
 			pids[nr++] = thread__tid(parent);
 			break;
 		}
+		thread__put(thread);
 		thread = parent;
 	}
+	thread__put(thread);
 
 	err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
 	if (!err && trace->filter_pids.map)
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
reviewer Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Namhyung Kim

I've found some leaks from 'perf trace -a'. It seems there are more leaks but this is what I can find for now.

Thanks,
Ian

Quoted 31 lines
---
 tools/perf/builtin-trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +3 -2
index 3d0c0076884d34cb..10cd99888a9a11b5 100644
@@ -2835,7 +2835,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
        e_machine = thread__e_machine(thread, trace->host);
        sc = trace__syscall_info(trace, evsel, e_machine, id);
        if (sc == NULL)
-               return -1;
+               goto out_put;
        ttrace = thread__trace(thread, trace);
        /*
         * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
@@ -4123,8 +4123,10 @@ static int trace__set_filter_loop_pids(struct trace *trace)
                        pids[nr++] = thread__tid(parent);
                        break;
                }
+               thread__put(thread);
                thread = parent;
        }
+       thread__put(thread);
 
        err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
        if (!err && trace->filter_pids.map)
--

2.49.0.472.ge94155a9ec-goog

#2 lore raw
In reply to Namhyung Kim

Hello Namhyung,

Quoted 24 lines · Namhyung Kim

I've found some leaks from 'perf trace -a'. It seems there are more leaks but this is what I can find for now.

---
 tools/perf/builtin-trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +1 -1
index 3d0c0076884d34cb..10cd99888a9a11b5 100644
@@ -2835,7 +2835,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
        e_machine = thread__e_machine(thread, trace->host);
        sc = trace__syscall_info(trace, evsel, e_machine, id);
        if (sc == NULL)
-               return -1;
+               goto out_put;
        ttrace = thread__trace(thread, trace);
        /*
         * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()

tools/perf/builtin-trace.c static int trace__set_filter_loop_pids(struct trace *trace) · line 4123

Quoted 1 line
tools/perf/builtin-trace.c +0 -0
@@ -4123,8 +4123,10 @@ static int trace__set_filter_loop_pids(struct trace *trace)
                        pids[nr++] = thread__tid(parent);

I suggest adding a:
thread_put(parent);
here, just before the break.

Quoted 10 lines
tools/perf/builtin-trace.c +2 -1
                        break;
                }
+               thread__put(thread);
                thread = parent;
        }
+       thread__put(thread);
 
        err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
        if (!err && trace->filter_pids.map)
--
Quoted 2 lines

2.49.0.472.ge94155a9ec-goog

Thanks,
Howard

author maintainer
#3 lore raw

Hello Howard,

Quoted 24 lines · Howard Chu

Hello Namhyung,

Quoted 21 lines · Namhyung Kim

I've found some leaks from 'perf trace -a'. It seems there are more leaks but this is what I can find for now.

---
 tools/perf/builtin-trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +1 -1
index 3d0c0076884d34cb..10cd99888a9a11b5 100644
@@ -2835,7 +2835,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
        e_machine = thread__e_machine(thread, trace->host);
        sc = trace__syscall_info(trace, evsel, e_machine, id);
        if (sc == NULL)
-               return -1;
+               goto out_put;
        ttrace = thread__trace(thread, trace);
Quoted 8 lines

tools/perf/builtin-trace.c static int trace__set_filter_loop_pids(struct trace *trace) · line 4123

Quoted 4 lines
tools/perf/builtin-trace.c +0 -0
        /*
         * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
@@ -4123,8 +4123,10 @@ static int trace__set_filter_loop_pids(struct trace *trace)
                        pids[nr++] = thread__tid(parent);

I suggest adding a:
thread_put(parent);
here, just before the break.

You're right, will add it.

Thanks,
Namhyung

Quoted 16 lines
Quoted 11 lines
tools/perf/builtin-trace.c +2 -1
                        break;
                }
+               thread__put(thread);
                thread = parent;
        }
+       thread__put(thread);
 
        err = evlist__append_tp_filter_pids(trace->evlist, nr, pids);
        if (!err && trace->filter_pids.map)
--
Quoted 2 lines

2.49.0.472.ge94155a9ec-goog

Thanks,
Howard