Commit 2fb63e09 authored by Yicong Yang's avatar Yicong Yang Committed by Junhao He
Browse files

perf stat: Fix memory leakage when trying perf on an offline CPU

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: 4804e011 ("perf stat: Use affinity for opening events")
Signed-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
Signed-off-by: default avatarJunhao He <hejunhao3@huawei.com>
parent 961139c6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;