libbpf: Fix memory leak and possible double-free in hashmap__clear
authorAndrii Nakryiko <andriin@fb.com>
Wed, 29 Apr 2020 01:21:04 +0000 (18:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 22 Jun 2020 07:30:51 +0000 (09:30 +0200)
commit269e7b43f2b4654f9f79e185ae425f2d72c6df37
tree53e82ae34c7709d59008daf3bcbab75c0d2c1ae3
parent072d23eef6003386d05424411522578fa75b6814
libbpf: Fix memory leak and possible double-free in hashmap__clear

[ Upstream commit 229bf8bf4d910510bc1a2fd0b89bd467cd71050d ]

Fix memory leak in hashmap_clear() not freeing hashmap_entry structs for each
of the remaining entries. Also NULL-out bucket list to prevent possible
double-free between hashmap__clear() and hashmap__free().

Running test_progs-asan flavor clearly showed this problem.

Reported-by: Alston Tang <alston64@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200429012111.277390-5-andriin@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/hashmap.c