perf disasm: Fix memory leak for locked operations
Ian Rogers
reviewerPATCH 1/2 perf disasm: Fix memory leak for locked operations
lock__parse calls disasm_line__parse passing &ops->locked.ins.name. Ensure ops->locked.ins.name is freed in lock__delete.
Found with lock/leak sanitizer.
--- tools/perf/util/disasm.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/disasm.c +1 -0
@@ -566,6 +566,7 @@ static void lock__delete(struct ins_operands *ops)ins_ops__delete (ops->locked.ops);zfree (&ops->locked.ops); +zfree (&ops->locked.ins.name);zfree (&ops->target.raw);zfree (&ops->target.name); }
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Ian Rogers
reviewerPATCH 2/2 perf test annotate: Dump trapping test in trap handler
Help to better identify the location of test failures but dumping the failing test in the trap handler.
--- tools/perf/tests/shell/annotate.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/annotate.sh +2 -1
@@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # perf annotate basic tests # SPDX-License-Identifier: GPL-2.0
@@ -28,6 +28,7 @@ cleanup() { } trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" cleanup exit 1 }
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Quoted 5 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Found with lock/leak sanitizer.
Applied both patches to perf-tools-next.
Thanks,
- Arnaldo
Quoted 19 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/disasm.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/disasm.c +1
-0@@ -566,6 +566,7 @@ static void lock__delete(struct ins_operands *ops)ins_ops__delete (ops->locked.ops);zfree (&ops->locked.ops); +zfree (&ops->locked.ins.name);zfree (&ops->target.raw);zfree (&ops->target.name); }Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Ian Rogers
reviewerQuoted 7 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Found with lock/leak sanitizer.
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Thanks, could you fix the commit message.
Thanks,
Ian
Quoted 23 lines
Thanks,
- Arnaldo
Quoted 19 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/disasm.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/disasm.c +1
-1@@ -566,6 +566,7 @@ static void lock__delete(struct ins_operands *ops)ins_ops__delete (ops->locked.ops);zfree (&ops->locked.ops); +zfree (&ops->locked.ins.name);zfree (&ops->target.raw);zfree (&ops->target.name); } --2.46.0.76.ge559c4bf1a-goog
Arnaldo Carvalho de Melo
maintainerQuoted 8 lines · Ian Rogers
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 4 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Found with lock/leak sanitizer.
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Thanks, could you fix the commit message.
Sure,
- Arnaldo
Ian Rogers
reviewerQuoted 12 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · Ian Rogers
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Found with lock/leak sanitizer.
Quoted 7 lines
Quoted 5 lines
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Thanks, could you fix the commit message.
Sure,
Also, it'd be good if maybe Namhyung could take a look. I did things this way as it made sense to me, but we have nested things going on and potentially the free would be more natural in ins_ops__delete.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerQuoted 14 lines · Ian Rogers
Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Ian Rogers
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Found with lock/leak sanitizer.
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks, could you fix the commit message.
Sure,
Also, it'd be good if maybe Namhyung could take a look. I did things this way as it made sense to me, but we have nested things going on and potentially the free would be more natural in
ins_ops__delete.
ins_ops__delete() would have to look it is operating on a lock operation to access the right member of the unnamed union (locked) to get that string pointer to free.
lock__delete() is the 'lock' destructor, that knows these details, so its the right place to do the freeing.
I.e.:
static struct ins_ops lock_ops = {
.free = lock__delete,
.parse = lock__parse,
.scnprintf = lock__scnprintf,
};
When it was introduced:
commit c46219ac34f0f365bac700ca6a10ef979c643233
Author: Arnaldo Carvalho de Melo <[email protected]> Date: Sat May 12 13:26:20 2012 -0300
perf annotate: Introduce ->free() method in ins_ops
So that we don't special case disasm_line__free, allowing each instruction class to provide a specialized destructor, like is needed for 'lock'.
- Arnaldo
Hi Ian,
Quoted 19 lines · Ian Rogers
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 14 lines · Ian Rogers
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Found with lock/leak sanitizer.
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Thanks, could you fix the commit message.
Sure,
Also, it'd be good if maybe Namhyung could take a look. I did things this way as it made sense to me, but we have nested things going on and potentially the free would be more natural in
ins_ops__delete.
Looks good to me.
Thanks,
Namhyung
Ian Rogers
reviewerQuoted 27 lines · Namhyung Kim
Hi Ian,
Quoted 23 lines · Ian Rogers
Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 8 lines · Ian Rogers
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 4 lines · Ian Rogers
lock__parsecallsdisasm_line__parsepassing&ops->locked.ins.name. Ensureops->locked.ins.nameis freed inlock__delete.Quoted 7 lines
Quoted 1 line
Quoted 1 line
Found with lock/leak sanitizer.
Ooops, I meant address/leak sanitizer.
Quoted 1 line
Applied both patches to perf-tools-next.
Thanks, could you fix the commit message.
Sure,
Quoted 7 lines
Quoted 3 lines
Also, it'd be good if maybe Namhyung could take a look. I did things this way as it made sense to me, but we have nested things going on and potentially the free would be more natural in
ins_ops__delete.Looks good to me.
Acked-by Namhyung Kim <[email protected]>
Thanks Namhyung, thanks Arnaldo. I think git blame said Namhyung because of a refactoring. I'm glad the free is in the correct location.
Thanks,
Ian