Skip to content

Commit fa55ef1

Browse files
Yuuoniyborkmann
authored andcommitted
bpftool: Fix memory leak in do_build_table_cb
strdup() allocates memory for path. We need to release the memory in the following error path. Add free() to avoid memory leak. Fixes: 8f18473 ("bpftool: Switch to libbpf's hashmap for pinned paths of BPF objects") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20221206071906.806384-1-linmq006@gmail.com
1 parent b54b600 commit fa55ef1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tools/bpf/bpftool/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ static int do_build_table_cb(const char *fpath, const struct stat *sb,
501501
if (err) {
502502
p_err("failed to append entry to hashmap for ID %u, path '%s': %s",
503503
pinned_info.id, path, strerror(errno));
504+
free(path);
504505
goto out_close;
505506
}
506507

0 commit comments

Comments
 (0)