Skip to content

Commit

Permalink
tools: Free BTF objects at various locations
Browse files Browse the repository at this point in the history
[ Upstream commit 369e955 ]

Make sure to call btf__free() (and not simply free(), which does not
free all pointers stored in the struct) on pointers to struct btf
objects retrieved at various locations.

These were found while updating the calls to btf__get_from_id().

Fixes: 999d82c ("tools/bpf: enhance test_btf file testing to test func info")
Fixes: 254471e ("tools/bpf: bpftool: add support for func types")
Fixes: 7b612e2 ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs")
Fixes: d56354d ("perf tools: Save bpf_prog_info and BTF of new BPF programs")
Fixes: 47c09d6 ("bpftool: Introduce "prog profile" command")
Fixes: fa853c4 ("perf stat: Enable counting events for BPF programs")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210729162028.29512-5-quentin@isovalent.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
qmonnet authored and gregkh committed Sep 15, 2021
1 parent 8aa52c3 commit e58f521
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tools/bpf/bpftool/prog.c
Expand Up @@ -778,6 +778,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
kernel_syms_destroy(&dd);
}

btf__free(btf);

return 0;
}

Expand Down Expand Up @@ -1897,8 +1899,8 @@ static char *profile_target_name(int tgt_fd)
struct bpf_prog_info_linear *info_linear;
struct bpf_func_info *func_info;
const struct btf_type *t;
struct btf *btf = NULL;
char *name = NULL;
struct btf *btf;

info_linear = bpf_program__get_prog_info_linear(
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
Expand All @@ -1922,6 +1924,7 @@ static char *profile_target_name(int tgt_fd)
}
name = strdup(btf__name_by_offset(btf, t->name_off));
out:
btf__free(btf);
free(info_linear);
return name;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/bpf-event.c
Expand Up @@ -296,7 +296,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,

out:
free(info_linear);
free(btf);
btf__free(btf);
return err ? -1 : 0;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ static void perf_env__add_bpf_info(struct perf_env *env, u32 id)
perf_env__fetch_btf(env, btf_id, btf);

out:
free(btf);
btf__free(btf);
close(fd);
}

Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/bpf_counter.c
Expand Up @@ -74,8 +74,8 @@ static char *bpf_target_prog_name(int tgt_fd)
struct bpf_prog_info_linear *info_linear;
struct bpf_func_info *func_info;
const struct btf_type *t;
struct btf *btf = NULL;
char *name = NULL;
struct btf *btf;

info_linear = bpf_program__get_prog_info_linear(
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
Expand All @@ -99,6 +99,7 @@ static char *bpf_target_prog_name(int tgt_fd)
}
name = strdup(btf__name_by_offset(btf, t->name_off));
out:
btf__free(btf);
free(info_linear);
return name;
}
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/btf.c
Expand Up @@ -4384,6 +4384,7 @@ static void do_test_file(unsigned int test_num)
fprintf(stderr, "OK");

done:
btf__free(btf);
free(func_info);
bpf_object__close(obj);
}
Expand Down

0 comments on commit e58f521

Please sign in to comment.