mempool: rework mempool_cleanup() to only release freed tiles
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Feb 2023 12:44:51 +0000 (13:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Feb 2023 14:03:53 +0000 (15:03 +0100)
commita2b052b29f8bc141e94a4af95d1653a38a57eaeb
tree0a64316b0a0f7f163164b74e0d50c5a1dc6bca49
parent4392b983b8e765a25c7bf081c06e8ecc37425274
mempool: rework mempool_cleanup() to only release freed tiles

This substantially reworks mempool_cleanup() so that it releases pools
with all freed tiles only, but keeps all pools with still-allocated
tiles around.

This is more correct, as the previous implementation just released all
pools regardless if anything was still used or not. This would make
valgrind shut up but would just hide memory leaks altogether. Moreover
if called during regular runtime of a program would result in bad memory
accesses all over.

Hence, let's add a proper implementation and only trim pools we really
know are empty.

This way we can safely call these functions later, when under memory
pressure, at any time.
src/basic/hashmap.c
src/basic/hashmap.h
src/basic/mempool.c
src/basic/mempool.h