diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2015-11-25 05:34:32 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-11-25 14:36:35 -0500 |
commit | 4d3b16269059eee12dc572848191c8e4e7bd24b3 (patch) | |
tree | 9eca24ef311d1ba2d8cc4167f281879f02dbe50f | |
parent | 32abc2ede536aae52978d6c0a8944eb1df14f460 (diff) |
perf probe: Fix to free temporal Dwarf_Frame correctly
The commit 05c8d802fa52 ("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: 05c8d802fa52 ("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>
-rw-r--r-- | tools/perf/util/probe-finder.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 1cab05a3831e..2be10fb27172 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -654,6 +654,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod, | |||
654 | static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) | 654 | static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) |
655 | { | 655 | { |
656 | Dwarf_Attribute fb_attr; | 656 | Dwarf_Attribute fb_attr; |
657 | Dwarf_Frame *frame = NULL; | ||
657 | size_t nops; | 658 | size_t nops; |
658 | int ret; | 659 | int ret; |
659 | 660 | ||
@@ -683,26 +684,24 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
683 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); | 684 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); |
684 | if (ret <= 0 || nops == 0) { | 685 | if (ret <= 0 || nops == 0) { |
685 | pf->fb_ops = NULL; | 686 | pf->fb_ops = NULL; |
686 | ret = 0; | ||
687 | #if _ELFUTILS_PREREQ(0, 142) | 687 | #if _ELFUTILS_PREREQ(0, 142) |
688 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && | 688 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
689 | pf->cfi != NULL) { | 689 | pf->cfi != NULL) { |
690 | Dwarf_Frame *frame = NULL; | ||
691 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || | 690 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || |
692 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { | 691 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { |
693 | pr_warning("Failed to get call frame on 0x%jx\n", | 692 | pr_warning("Failed to get call frame on 0x%jx\n", |
694 | (uintmax_t)pf->addr); | 693 | (uintmax_t)pf->addr); |
695 | ret = -ENOENT; | 694 | free(frame); |
695 | return -ENOENT; | ||
696 | } | 696 | } |
697 | free(frame); | ||
698 | #endif | 697 | #endif |
699 | } | 698 | } |
700 | 699 | ||
701 | /* Call finder's callback handler */ | 700 | /* Call finder's callback handler */ |
702 | if (ret >= 0) | 701 | ret = pf->callback(sc_die, pf); |
703 | ret = pf->callback(sc_die, pf); | ||
704 | 702 | ||
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); | ||
706 | pf->fb_ops = NULL; | 705 | pf->fb_ops = NULL; |
707 | 706 | ||
708 | return ret; | 707 | return ret; |