[PATCH 1/2] tools/bpf/bpftool: Reset vmlinux BTF after map dump
From: Yichong Chen
Date: Sun Jun 21 2026 - 22:35:01 EST
map dump frees the global btf_vmlinux object.
In batch mode, a later map dump can reuse the stale pointer.
Reset the global pointer after freeing it.
Signed-off-by: Yichong Chen <chenyichong@xxxxxxxxxxxxx>
---
tools/bpf/bpftool/map.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 7ebf7dbcfba4..8aab9ce743cb 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -790,6 +790,12 @@ static int maps_have_btf(int *fds, int nb_fds)
static struct btf *btf_vmlinux;
+static void free_btf_vmlinux(void)
+{
+ btf__free(btf_vmlinux);
+ btf_vmlinux = NULL;
+}
+
static int get_map_kv_btf(const struct bpf_map_info *info, struct btf **btf)
{
int err = 0;
@@ -958,7 +964,7 @@ static int do_dump(int argc, char **argv)
close(fds[i]);
exit_free:
free(fds);
- btf__free(btf_vmlinux);
+ free_btf_vmlinux();
return err;
}
--
2.51.0