bpftool: Fix memory leak in dump_xx_nlmsg on realloc failure
authorYuan Chen <chenyuan@kylinos.cn>
Fri, 20 Jun 2025 01:21:33 +0000 (09:21 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 20 Jun 2025 18:32:36 +0000 (11:32 -0700)
commit99fe8af069a9fa5b09140518b1364e35713a642e
treec4732a169dcf066cd1d8836db4f766296751b1da
parentf8b19aeca1652fcadefce8529cd85e5fd475dd69
bpftool: Fix memory leak in dump_xx_nlmsg on realloc failure

In function dump_xx_nlmsg(), when realloc() fails to allocate memory,
the original pointer to the buffer is overwritten with NULL. This causes
a memory leak because the previously allocated buffer becomes unreachable
without being freed.

Fixes: 7900efc19214 ("tools/bpf: bpftool: improve output format for bpftool net")
Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/r/20250620012133.14819-1-chenyuan_fl@163.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/bpf/bpftool/net.c