lkml.org 
[lkml]   [2022]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH bpf-next 4/5] selftest/bpf: Fix memory leak in kprobe_multi_test
Date
From: Xu Kuohai <xukuohai@huawei.com>

The get_syms() function in kprobe_multi_test.c does not free the string
memory allocated by sscanf correctly. Fix it.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
---
.../bpf/prog_tests/kprobe_multi_test.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index d457a55ff408..07dd2c5b7f98 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -360,15 +360,14 @@ static int get_syms(char ***symsp, size_t *cntp)
* to them. Filter out the current culprits - arch_cpu_idle
* and rcu_* functions.
*/
- if (!strcmp(name, "arch_cpu_idle"))
- continue;
- if (!strncmp(name, "rcu_", 4))
- continue;
- if (!strcmp(name, "bpf_dispatcher_xdp_func"))
- continue;
- if (!strncmp(name, "__ftrace_invalid_address__",
- sizeof("__ftrace_invalid_address__") - 1))
+ if (!strcmp(name, "arch_cpu_idle") ||
+ !strncmp(name, "rcu_", 4) ||
+ !strcmp(name, "bpf_dispatcher_xdp_func") ||
+ !strncmp(name, "__ftrace_invalid_address__",
+ sizeof("__ftrace_invalid_address__") - 1)) {
+ free(name);
continue;
+ }
err = hashmap__add(map, name, NULL);
if (err) {
free(name);
@@ -394,7 +393,7 @@ static int get_syms(char ***symsp, size_t *cntp)
hashmap__free(map);
if (err) {
for (i = 0; i < cnt; i++)
- free(syms[cnt]);
+ free(syms[i]);
free(syms);
}
return err;
--
2.25.1
\
 
 \ /
  Last update: 2022-10-09 15:02    [W:0.087 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site