mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
tools: Free BTF objects at various locations
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:999d82cbc0
("tools/bpf: enhance test_btf file testing to test func info") Fixes:254471e57a
("tools/bpf: bpftool: add support for func types") Fixes:7b612e291a
("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs") Fixes:d56354dc49
("perf tools: Save bpf_prog_info and BTF of new BPF programs") Fixes:47c09d6a9f
("bpftool: Introduce "prog profile" command") Fixes:fa853c4b83
("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
This commit is contained in:
parent
6cc93e2f2c
commit
369e955b3d
4 changed files with 9 additions and 4 deletions
|
@ -781,6 +781,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
|
||||||
kernel_syms_destroy(&dd);
|
kernel_syms_destroy(&dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btf__free(btf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2002,8 +2004,8 @@ static char *profile_target_name(int tgt_fd)
|
||||||
struct bpf_prog_info_linear *info_linear;
|
struct bpf_prog_info_linear *info_linear;
|
||||||
struct bpf_func_info *func_info;
|
struct bpf_func_info *func_info;
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
|
struct btf *btf = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
struct btf *btf;
|
|
||||||
|
|
||||||
info_linear = bpf_program__get_prog_info_linear(
|
info_linear = bpf_program__get_prog_info_linear(
|
||||||
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
|
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
|
||||||
|
@ -2027,6 +2029,7 @@ static char *profile_target_name(int tgt_fd)
|
||||||
}
|
}
|
||||||
name = strdup(btf__name_by_offset(btf, t->name_off));
|
name = strdup(btf__name_by_offset(btf, t->name_off));
|
||||||
out:
|
out:
|
||||||
|
btf__free(btf);
|
||||||
free(info_linear);
|
free(info_linear);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,7 +296,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(info_linear);
|
free(info_linear);
|
||||||
free(btf);
|
btf__free(btf);
|
||||||
return err ? -1 : 0;
|
return err ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
perf_env__fetch_btf(env, btf_id, btf);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(btf);
|
btf__free(btf);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ static char *bpf_target_prog_name(int tgt_fd)
|
||||||
struct bpf_prog_info_linear *info_linear;
|
struct bpf_prog_info_linear *info_linear;
|
||||||
struct bpf_func_info *func_info;
|
struct bpf_func_info *func_info;
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
|
struct btf *btf = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
struct btf *btf;
|
|
||||||
|
|
||||||
info_linear = bpf_program__get_prog_info_linear(
|
info_linear = bpf_program__get_prog_info_linear(
|
||||||
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
|
tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO);
|
||||||
|
@ -89,6 +89,7 @@ static char *bpf_target_prog_name(int tgt_fd)
|
||||||
}
|
}
|
||||||
name = strdup(btf__name_by_offset(btf, t->name_off));
|
name = strdup(btf__name_by_offset(btf, t->name_off));
|
||||||
out:
|
out:
|
||||||
|
btf__free(btf);
|
||||||
free(info_linear);
|
free(info_linear);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4386,6 +4386,7 @@ skip:
|
||||||
fprintf(stderr, "OK");
|
fprintf(stderr, "OK");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
btf__free(btf);
|
||||||
free(func_info);
|
free(func_info);
|
||||||
bpf_object__close(obj);
|
bpf_object__close(obj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue