Skip to content

Commit 4d3b162

Browse files
mhiramathitachiacmel
authored andcommitted
perf probe: Fix to free temporal Dwarf_Frame correctly
The commit 05c8d80 ("perf probe: Fix to free temporal Dwarf_Frame") tried to fix the memory leak of Dwarf_Frame, but it released the frame at wrong point. Since the dwarf_frame_cfa(frame, &pf->fb_ops, &nops) can return an address inside the frame data structure to pf->fb_ops, we can not release the frame before using pf->fb_ops. This reverts the commit and releases the frame afterwards (right before returning from call_probe_finder) correctly. Reported-and-Tested-by: Arnaldo Carvalho de Melo <acme@kernel.org> Reported-by: Michael Petlan <mpetlan@redhat.com> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Wang Nan <wangnan0@huawei.com> Fixes: 05c8d80 ("perf probe: Fix to free temporal Dwarf_Frame") LPU-Reference: 20151125103432.1473.31009.stgit@localhost.localdomain Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 32abc2e commit 4d3b162

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎tools/perf/util/probe-finder.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,
654654
static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)
655655
{
656656
Dwarf_Attribute fb_attr;
657+
Dwarf_Frame *frame = NULL;
657658
size_t nops;
658659
int ret;
659660

@@ -683,26 +684,24 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf)
683684
ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
684685
if (ret <= 0 || nops == 0) {
685686
pf->fb_ops = NULL;
686-
ret = 0;
687687
#if _ELFUTILS_PREREQ(0, 142)
688688
} else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
689689
pf->cfi != NULL) {
690-
Dwarf_Frame *frame = NULL;
691690
if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 ||
692691
dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) {
693692
pr_warning("Failed to get call frame on 0x%jx\n",
694693
(uintmax_t)pf->addr);
695-
ret = -ENOENT;
694+
free(frame);
695+
return -ENOENT;
696696
}
697-
free(frame);
698697
#endif
699698
}
700699

701700
/* Call finder's callback handler */
702-
if (ret >= 0)
703-
ret = pf->callback(sc_die, pf);
701+
ret = pf->callback(sc_die, pf);
704702

705-
/* *pf->fb_ops will be cached in libdw. Don't free it. */
703+
/* Since *pf->fb_ops can be a part of frame. we should free it here. */
704+
free(frame);
706705
pf->fb_ops = NULL;
707706

708707
return ret;

0 commit comments

Comments
 (0)