Commit f7958752 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Clean up btf and btf_dump in dump_datasec test

Free up used resources at the end and on error. Also make it more
obvious that there is btf__parse() call that creates struct btf
instance.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Reviewed-by: default avatarHengqi Chen <hengqi.chen@gmail.com>
Link: https://lore.kernel.org/bpf/20211107165521.9240-7-andrii@kernel.org
parent 5309b516
...@@ -814,21 +814,25 @@ static void test_btf_datasec(struct btf *btf, struct btf_dump *d, char *str, ...@@ -814,21 +814,25 @@ static void test_btf_datasec(struct btf *btf, struct btf_dump *d, char *str,
static void test_btf_dump_datasec_data(char *str) static void test_btf_dump_datasec_data(char *str)
{ {
struct btf *btf = btf__parse("xdping_kern.o", NULL); struct btf *btf;
struct btf_dump_opts opts = { .ctx = str }; struct btf_dump_opts opts = { .ctx = str };
char license[4] = "GPL"; char license[4] = "GPL";
struct btf_dump *d; struct btf_dump *d;
btf = btf__parse("xdping_kern.o", NULL);
if (!ASSERT_OK_PTR(btf, "xdping_kern.o BTF not found")) if (!ASSERT_OK_PTR(btf, "xdping_kern.o BTF not found"))
return; return;
d = btf_dump__new(btf, NULL, &opts, btf_dump_snprintf); d = btf_dump__new(btf, NULL, &opts, btf_dump_snprintf);
if (!ASSERT_OK_PTR(d, "could not create BTF dump")) if (!ASSERT_OK_PTR(d, "could not create BTF dump"))
return; goto out;
test_btf_datasec(btf, d, str, "license", test_btf_datasec(btf, d, str, "license",
"SEC(\"license\") char[4] _license = (char[4])['G','P','L',];", "SEC(\"license\") char[4] _license = (char[4])['G','P','L',];",
license, sizeof(license)); license, sizeof(license));
out:
btf_dump__free(d);
btf__free(btf);
} }
void test_btf_dump() { void test_btf_dump() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment