Fixed two memory leak issues of the Perf tool
Yicong Yang (2): perf parse-events: Fix one memory leakage issue perf stat: Fix memory leakage when trying perf on an offline CPU
tools/perf/builtin-stat.c | 2 ++ tools/perf/util/parse-events.c | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-)
From: Yicong Yang yangyicong@hisilicon.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8MEWF CVE: NA
--------------------------------
ASan complains one memory leakage issue: ==2266938==ERROR: LeakSanitizer: detected memory leaks Direct leak of 14821 byte(s) in 217 object(s) allocated from: #0 0xffff96712468 in realloc (libasan.so.6+0xa5468) #1 0xffff956b0dac (/usr/lib64/libc.so.6+0x73dac) #2 0xffff9573097c in __asprintf_chk (/usr/lib64/libc.so.6+0xf397c) #3 0x4de620 in asprintf usr/include/aarch64-linux-gnu/bits/stdio2.h:178 #4 0x4de620 in print_sdt_events util/parse-events.c:2669 #5 0x4432e0 in cmd_list work/tools/perf/builtin-list.c:87 #6 0x4b85c4 in run_builtin work/tools/perf/perf.c:312 #7 0x431a90 in handle_internal_command work/tools/perf/perf.c:364 #8 0x431a90 in run_argv work/tools/perf/perf.c:408 #9 0x431a90 in main work/tools/perf/perf.c:538 #10 0xffff95667ff8 (/usr/lib64/libc.so.6+0x2aff8) #11 0xffff956680c4 in __libc_start_main (/usr/lib64/libc.so.6+0x2b0c4) #12 0x431d3c (/tmp/perf_asan+0x431d3c) SUMMARY: AddressSanitizer: 14821 byte(s) leaked in 217 allocation(s).
Fix this.
Fixes: 40218daea1db ("perf list: Show SDT and pre-cached events") Signed-off-by: Yicong Yang yangyicong@hisilicon.com Signed-off-by: Junhao He hejunhao3@huawei.com --- tools/perf/util/parse-events.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 64d148f6032c..722aaf7a40c8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2637,13 +2637,12 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob, struct probe_cache *pcache; struct probe_cache_entry *ent; struct strlist *bidlist, *sdtlist; - struct strlist_config cfg = {.dont_dupstr = true}; - struct str_node *nd, *nd2; char *buf, *path, *ptr = NULL; + struct str_node *nd, *nd2; bool show_detail = false; int ret;
- sdtlist = strlist__new(NULL, &cfg); + sdtlist = strlist__new(NULL, NULL); if (!sdtlist) { pr_debug("Failed to allocate new strlist for SDT\n"); return; @@ -2670,6 +2669,8 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob, ent->pev.event, nd->s); if (ret > 0) strlist__add(sdtlist, buf); + + free(buf); } probe_cache__delete(pcache); }
From: Yicong Yang yangyicong@hisilicon.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8MEWF CVE: NA
--------------------------------
When try to open perf on an offline CPU, ASan complains: ==2316857==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 512 byte(s) in 1 object(s) allocated from: #0 0xffff9e774290 in __interceptor_calloc (libasan.so.6+0xa5290) #1 0x62b34c in affinity__setup (/tmp/perf_asan+0x62b34c) #2 0x540d70 in cmd_stat (/tmp/perf_asan+0x540d70) #3 0x59e7e4 in run_builtin (/tmp/perf_asan+0x59e7e4) #4 0x456778 in main (/tmp/perf_asan+0x456778) #5 0xffff9d9c4ff8 (/usr/lib64/libc.so.6+0x2aff8) #6 0xffff9d9c50c4 in __libc_start_main (/usr/lib64/libc.so.6+0x2b0c4) #7 0x523f60 (/tmp/perf_asan+0x523f60)
Direct leak of 512 byte(s) in 1 object(s) allocated from: #0 0xffff9e774290 in __interceptor_calloc (libasan.so.6+0xa5290) #1 0x62b370 in affinity__setup (/tmp/perf_asan+0x62b370) #2 0x540d70 in cmd_stat (/tmp/perf_asan+0x540d70) #3 0x59e7e4 in run_builtin (/tmp/perf_asan+0x59e7e4) #4 0x456778 in main (/tmp/perf_asan+0x456778) #5 0xffff9d9c4ff8 (/usr/lib64/libc.so.6+0x2aff8) #6 0xffff9d9c50c4 in __libc_start_main (/usr/lib64/libc.so.6+0x2b0c4) #7 0x523f60 (/tmp/perf_asan+0x523f60)
Fix this.
Fixes: 4804e0111662 ("perf stat: Use affinity for opening events") Signed-off-by: Yicong Yang yangyicong@hisilicon.com Signed-off-by: Junhao He hejunhao3@huawei.com --- tools/perf/builtin-stat.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 89e80a3bc9c3..1f8a23a1b867 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -768,6 +768,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
switch (stat_handle_error(counter)) { case COUNTER_FATAL: + affinity__cleanup(&affinity); return -1; case COUNTER_RETRY: goto try_again; @@ -813,6 +814,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
switch (stat_handle_error(counter)) { case COUNTER_FATAL: + affinity__cleanup(&affinity); return -1; case COUNTER_RETRY: goto try_again_reset;
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/10113 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/A...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/10113 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/A...