提交 59c1b296 编写于 作者: Q Quentin Monnet 提交者: Zheng Zengkai

tools: Free BTF objects at various locations

mainline inclusion
from mainline-5.15-rc1
commit 369e955b
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=369e955b3d1c12f6ec2e51a95911bb80ada55d79

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

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: 999d82cb ("tools/bpf: enhance test_btf file testing to test func info")
Fixes: 254471e5 ("tools/bpf: bpftool: add support for func types")
Fixes: 7b612e29 ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs")
Fixes: d56354dc ("perf tools: Save bpf_prog_info and BTF of new BPF programs")
Fixes: 47c09d6a ("bpftool: Introduce "prog profile" command")
Fixes: fa853c4b ("perf stat: Enable counting events for BPF programs")
Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210729162028.29512-5-quentin@isovalent.com
(cherry picked from commit 369e955b)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 b7045369
......@@ -783,6 +783,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
kernel_syms_destroy(&dd);
}
btf__free(btf);
return 0;
}
......@@ -1976,8 +1978,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);
......@@ -2001,6 +2003,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;
}
......
......@@ -293,7 +293,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;
}
......@@ -483,7 +483,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);
}
......
......@@ -63,8 +63,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);
......@@ -88,6 +88,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;
}
......
......@@ -4254,6 +4254,7 @@ static void do_test_file(unsigned int test_num)
fprintf(stderr, "OK");
done:
btf__free(btf);
free(func_info);
bpf_object__close(obj);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册