提交 9bbd7b3a 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

selftests/bpf: Free per-cpu values array in bpf_iter selftest

mainline inclusion
from mainline-5.17-rc1
commit b8b26e58
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b8b26e585f3a0fbcee1032c622f046787da57390

-------------------------------------------------

Array holding per-cpu values wasn't freed. Fix that.
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211107165521.9240-5-andrii@kernel.org
(cherry picked from commit b8b26e58)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 55c47646
...@@ -674,14 +674,13 @@ static void test_bpf_percpu_hash_map(void) ...@@ -674,14 +674,13 @@ static void test_bpf_percpu_hash_map(void)
char buf[64]; char buf[64];
void *val; void *val;
val = malloc(8 * bpf_num_possible_cpus());
skel = bpf_iter_bpf_percpu_hash_map__open(); skel = bpf_iter_bpf_percpu_hash_map__open();
if (CHECK(!skel, "bpf_iter_bpf_percpu_hash_map__open", if (CHECK(!skel, "bpf_iter_bpf_percpu_hash_map__open",
"skeleton open failed\n")) "skeleton open failed\n"))
return; return;
skel->rodata->num_cpus = bpf_num_possible_cpus(); skel->rodata->num_cpus = bpf_num_possible_cpus();
val = malloc(8 * bpf_num_possible_cpus());
err = bpf_iter_bpf_percpu_hash_map__load(skel); err = bpf_iter_bpf_percpu_hash_map__load(skel);
if (CHECK(!skel, "bpf_iter_bpf_percpu_hash_map__load", if (CHECK(!skel, "bpf_iter_bpf_percpu_hash_map__load",
...@@ -746,6 +745,7 @@ static void test_bpf_percpu_hash_map(void) ...@@ -746,6 +745,7 @@ static void test_bpf_percpu_hash_map(void)
bpf_link__destroy(link); bpf_link__destroy(link);
out: out:
bpf_iter_bpf_percpu_hash_map__destroy(skel); bpf_iter_bpf_percpu_hash_map__destroy(skel);
free(val);
} }
static void test_bpf_array_map(void) static void test_bpf_array_map(void)
...@@ -846,14 +846,13 @@ static void test_bpf_percpu_array_map(void) ...@@ -846,14 +846,13 @@ static void test_bpf_percpu_array_map(void)
void *val; void *val;
int len; int len;
val = malloc(8 * bpf_num_possible_cpus());
skel = bpf_iter_bpf_percpu_array_map__open(); skel = bpf_iter_bpf_percpu_array_map__open();
if (CHECK(!skel, "bpf_iter_bpf_percpu_array_map__open", if (CHECK(!skel, "bpf_iter_bpf_percpu_array_map__open",
"skeleton open failed\n")) "skeleton open failed\n"))
return; return;
skel->rodata->num_cpus = bpf_num_possible_cpus(); skel->rodata->num_cpus = bpf_num_possible_cpus();
val = malloc(8 * bpf_num_possible_cpus());
err = bpf_iter_bpf_percpu_array_map__load(skel); err = bpf_iter_bpf_percpu_array_map__load(skel);
if (CHECK(!skel, "bpf_iter_bpf_percpu_array_map__load", if (CHECK(!skel, "bpf_iter_bpf_percpu_array_map__load",
...@@ -909,6 +908,7 @@ static void test_bpf_percpu_array_map(void) ...@@ -909,6 +908,7 @@ static void test_bpf_percpu_array_map(void)
bpf_link__destroy(link); bpf_link__destroy(link);
out: out:
bpf_iter_bpf_percpu_array_map__destroy(skel); bpf_iter_bpf_percpu_array_map__destroy(skel);
free(val);
} }
static void test_bpf_sk_storage_map(void) static void test_bpf_sk_storage_map(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册