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.
This commit is contained in:
Lennart Poettering
2023-02-17 15:03:53 +01:00
parent 4392b983b8
commit a2b052b29f
4 changed files with 92 additions and 12 deletions
+1 -1
View File
@@ -25,4 +25,4 @@ static struct mempool pool_name = { \
__attribute__((weak)) bool mempool_enabled(void);
void mempool_drop(struct mempool *mp);
void mempool_trim(struct mempool *mp);