Skip to content

Commit 8b2494f

Browse files
committed
btf_unit_test: Remember to free memory
It is a bad habit to rely on process exit to free memory. Add proper memory free operations. Using checker command: valgrind --leak-check=yes ./btf_unit_test Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
1 parent 9ed0567 commit 8b2494f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

AF_XDP-interaction/btf_unit_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int init_btf_info_via_bpf_object(struct bpf_object *bpf_obj)
9898
xdp_hints_rx_time.btf_type_id = xsk_btf__btf_type_id(xbi);
9999
xdp_hints_rx_time.xbi = xbi;
100100
}
101+
// xsk_btf__free_xdp_hint(xbi);
101102

102103
xbi = setup_btf_info(btf, "xdp_hints_mark");
103104
if (xbi) {
@@ -127,10 +128,15 @@ int main(int argc, char **argv)
127128
printf("ERR(%d): Failed loading BTF info", err);
128129
return EXIT_FAIL_BTF;
129130
}
131+
/* Teardown structs and memory again */
132+
xsk_btf__free_xdp_hint(xdp_hints_rx_time.xbi);
133+
xsk_btf__free_xdp_hint(xdp_hints_mark.xbi);
134+
bpf_object__close(bpf_obj);
130135

131136
bpf_obj = load_bpf_object("btf_unit_test_bpf.o");
132137
if (!bpf_obj)
133138
return EXIT_FAIL_BPF;
139+
bpf_object__close(bpf_obj);
134140

135141

136142
return EXIT_OK;

0 commit comments

Comments
 (0)