Skip to contentSkip to conversation

Perf fix two memory leakage

PATCH In review Yicong Yang 3 participants 6 messages Dec 7, 2023 – Dec 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Perf fix two memory leakage

From: Yicong Yang <[email protected]>

ASan reports two memory leakage in the raw trace dump mode perf report -D. One is in the framework and can be reproduced when using hisi_ptt and arm_spe, which is fixed in Patch 1/2. Another is in the hisi_ptt parser and fixed in Patch 2/2.

Yicong Yang (2):
perf header: Fix one memory leakage in
perf_event__fprintf_event_update()
perf hisi-ptt: Fix one memory leakage in
hisi_ptt_process_auxtrace_event()

 tools/perf/util/header.c   | 5 +++--
 tools/perf/util/hisi-ptt.c | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/2 perf header: Fix one memory leakage in perf_event__fprintf_event_update()

From: Yicong Yang <[email protected]>

When dump the raw trace by perf report -D ASan reports a memory leakage in perf_event__fprintf_event_update(). It shows that we allocated a temporary cpumap for dumping the CPUs but doesn't release it and it's not used elsewhere. Fix this by free the cpumap after the dumping.

Fixes c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function")
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/header.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/header.c +3 -2
index e86b9439ffee..7190f39ccd13 100644
@@ -4369,9 +4369,10 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp)
 		ret += fprintf(fp, "... ");
 
 		map = cpu_map__new_data(&ev->cpus.cpus);
-		if (map)
+		if (map) {
 			ret += cpu_map__fprintf(map, fp);
-		else
+			perf_cpu_map__put(map);
+		} else
 			ret += fprintf(fp, "failed to get cpus\n");
 		break;
 	default:
Signature · 1 line
2.24.0
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update()

Hello,

Quoted 9 lines · Yicong Yang

From: Yicong Yang <[email protected]>

When dump the raw trace by perf report -D ASan reports a memory leakage in perf_event__fprintf_event_update(). It shows that we allocated a temporary cpumap for dumping the CPUs but doesn't release it and it's not used elsewhere. Fix this by free the cpumap after the dumping.

Quoted 3 lines
Fixes c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function")
Cc Jiri Olsa <[email protected]>

Thanks,
Namhyung

Quoted 25 lines
---
 tools/perf/util/header.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/header.c +3 -3
index e86b9439ffee..7190f39ccd13 100644
@@ -4369,9 +4369,10 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp)
                ret += fprintf(fp, "... ");
 
                map = cpu_map__new_data(&ev->cpus.cpus);
-               if (map)
+               if (map) {
                        ret += cpu_map__fprintf(map, fp);
-               else
+                       perf_cpu_map__put(map);
+               } else
                        ret += fprintf(fp, "failed to get cpus\n");
                break;
        default:
--

2.24.0

#3 lore raw

PATCH 2/2 perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event()

In reply to Yicong Yang

From: Yicong Yang <[email protected]>

ASan complains a memory leakage in hisi_ptt_process_auxtrace_event() that the data buffer is not freed. Since currently we only support the raw dump trace mode, the data buffer is used only within this function. So fix this by freeing the data buffer before going out.

Fixes 5e91e57e6809 ("perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet")
---
 tools/perf/util/hisi-ptt.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/hisi-ptt.c +1 -0
index 43bd1ca62d58..52d0ce302ca0 100644
@@ -123,6 +123,7 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
 	if (dump_trace)
 		hisi_ptt_dump_event(ptt, data, size);
 
+	free(data);
 	return 0;
 }
 
Signature · 1 line
2.24.0
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event()

Quoted 10 lines · Yicong Yang

From: Yicong Yang <[email protected]>

ASan complains a memory leakage in hisi_ptt_process_auxtrace_event() that the data buffer is not freed. Since currently we only support the raw dump trace mode, the data buffer is used only within this function. So fix this by freeing the data buffer before going out.

Fixes 5e91e57e6809 ("perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet")

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/util/hisi-ptt.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/hisi-ptt.c +1 -1
index 43bd1ca62d58..52d0ce302ca0 100644
@@ -123,6 +123,7 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
        if (dump_trace)
                hisi_ptt_dump_event(ptt, data, size);
 
+       free(data);
        return 0;
 }
 
--

2.24.0

reviewer Reviewed-by on the v1 series
#5 lore raw
In reply to Yicong Yang
Quoted 14 lines · Yicong Yang

From: Yicong Yang <[email protected]>

ASan reports two memory leakage in the raw trace dump mode perf report -D. One is in the framework and can be reproduced when using hisi_ptt and arm_spe, which is fixed in Patch 1/2. Another is in the hisi_ptt parser and fixed in Patch 2/2.

Yicong Yang (2):
perf header: Fix one memory leakage in
perf_event__fprintf_event_update()
perf hisi-ptt: Fix one memory leakage in
hisi_ptt_process_auxtrace_event()

Quoted 3 lines
 tools/perf/util/header.c   | 5 +++--
 tools/perf/util/hisi-ptt.c | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

The series:

Thanks,
Ian

Quoted 3 lines

--
2.24.0