summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-08-03 16:46:26 +0200
committerLennart Poettering <lennart@poettering.net>2018-08-03 17:36:11 +0200
commit205c085bc36c2c61a09dc40621d8561b135d9b57 (patch)
tree7a0878d90a585ede89adc618d2181ef2742c4e5f /src/basic
parentb4f607433cac749b617e15b3d5d122322ed2bc71 (diff)
downloadsystemd-205c085bc36c2c61a09dc40621d8561b135d9b57.tar.gz
systemd-205c085bc36c2c61a09dc40621d8561b135d9b57.tar.bz2
systemd-205c085bc36c2c61a09dc40621d8561b135d9b57.zip
hashmap: add an explicit assert() for detecting when objects migrated between threads
When clients don't follow protocol and use the same object from different threads, then we previously would silently corrupt memory. With this assert we'll fail with an assert(). This doesn't fix anything but certainly makes mis-uses easier to detect and debug. Triggered by https://bugzilla.redhat.com/show_bug.cgi?id=1609349
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 65e22ccd21..44d718c83d 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -869,9 +869,11 @@ static void hashmap_free_no_clear(HashmapBase *h) {
assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0);
#endif
- if (h->from_pool)
+ if (h->from_pool) {
+ /* Ensure that the object didn't get migrated between threads. */
+ assert_se(is_main_thread());
mempool_free_tile(hashmap_type_info[h->type].mempool, h);
- else
+ } else
free(h);
}