Skip to content

Commit

Permalink
selftests/bpf: Clean up btf and btf_dump in dump_datasec test
Browse files Browse the repository at this point in the history
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: Andrii Nakryiko <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Reviewed-by: Hengqi Chen <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
anakryiko authored and Alexei Starovoitov committed Nov 7, 2021
1 parent 5309b51 commit f795875
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/btf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
struct btf *btf = btf__parse("xdping_kern.o", NULL);
struct btf *btf;
struct btf_dump_opts opts = { .ctx = str };
char license[4] = "GPL";
struct btf_dump *d;

btf = btf__parse("xdping_kern.o", NULL);
if (!ASSERT_OK_PTR(btf, "xdping_kern.o BTF not found"))
return;

d = btf_dump__new(btf, NULL, &opts, btf_dump_snprintf);
if (!ASSERT_OK_PTR(d, "could not create BTF dump"))
return;
goto out;

test_btf_datasec(btf, d, str, "license",
"SEC(\"license\") char[4] _license = (char[4])['G','P','L',];",
license, sizeof(license));
out:
btf_dump__free(d);
btf__free(btf);
}

void test_btf_dump() {
Expand Down

0 comments on commit f795875

Please sign in to comment.