提交 f40b3c79 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Free up resources used by inner map definition

mainline inclusion
from mainline-5.17-rc1
commit 8f7b239e
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=8f7b239ea8cfdc8e64c875ee417fed41431a1f37

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

It's not enough to just free(map->inner_map), as inner_map itself can
have extra memory allocated, like map name.

Fixes: 646f02ff ("libbpf: Add BTF-defined map-in-map support")
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Reviewed-by: NHengqi Chen <hengqi.chen@gmail.com>
Link: https://lore.kernel.org/bpf/20211107165521.9240-3-andrii@kernel.org
(cherry picked from commit 8f7b239e)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 0feb88c6
...@@ -9007,7 +9007,10 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd) ...@@ -9007,7 +9007,10 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd)
pr_warn("error: inner_map_fd already specified\n"); pr_warn("error: inner_map_fd already specified\n");
return libbpf_err(-EINVAL); return libbpf_err(-EINVAL);
} }
zfree(&map->inner_map); if (map->inner_map) {
bpf_map__destroy(map->inner_map);
zfree(&map->inner_map);
}
map->inner_map_fd = fd; map->inner_map_fd = fd;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册