summaryrefslogtreecommitdiffstats
path: root/src/basic/hashmap.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-02-14 13:44:51 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-17 15:03:53 +0100
commita2b052b29f8bc141e94a4af95d1653a38a57eaeb (patch)
tree0a64316b0a0f7f163164b74e0d50c5a1dc6bca49 /src/basic/hashmap.c
parentmempool: make mempool_free_tile() return NULL (diff)
downloadsystemd-a2b052b29f8bc141e94a4af95d1653a38a57eaeb.tar.xz
systemd-a2b052b29f8bc141e94a4af95d1653a38a57eaeb.zip
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.
Diffstat (limited to 'src/basic/hashmap.c')
-rw-r--r--src/basic/hashmap.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index c18c75d78c..75119866d4 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -274,7 +274,7 @@ static _used_ const struct hashmap_type_info hashmap_type_info[_HASHMAP_TYPE_MAX
},
};
-void hashmap_cleanup_pools(void) {
+void hashmap_trim_pools(void) {
int r;
/* The pool is only allocated by the main thread, but the memory can be passed to other
@@ -291,8 +291,8 @@ void hashmap_cleanup_pools(void) {
if (r != 1)
return (void) log_debug("Not cleaning up memory pools, running in multi-threaded process.");
- mempool_drop(&hashmap_pool);
- mempool_drop(&ordered_hashmap_pool);
+ mempool_trim(&hashmap_pool);
+ mempool_trim(&ordered_hashmap_pool);
}
#if VALGRIND