summaryrefslogtreecommitdiff
path: root/src/basic/hashmap.c
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2019-06-18 11:25:16 +0200
committerLennart Poettering <lennart@poettering.net>2019-06-18 13:59:12 +0200
commit31c9d74d500b6fad86f1ec26ab5bba156051e813 (patch)
tree6a882ed18ffd784903d55339c046acf1701717e2 /src/basic/hashmap.c
parent59da64738b69dad1ac9f3bb93a99ac695f0d41d4 (diff)
downloadsystemd-31c9d74d500b6fad86f1ec26ab5bba156051e813.tar.gz
hashmap: avoid using TLS in a destructor
Using C11 thread-local storage in destructors causes uninitialized read. Let's avoid that using a direct comparison instead of using the cached values. As this code path is taken only when compiled with -DVALGRIND=1, the performance cost shouldn't matter too much. Fixes #12814
Diffstat (limited to 'src/basic/hashmap.c')
-rw-r--r--src/basic/hashmap.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index c7bd7323a1..f244d767da 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -11,6 +11,7 @@
#include "macro.h"
#include "memory-util.h"
#include "mempool.h"
+#include "missing.h"
#include "process-util.h"
#include "random-util.h"
#include "set.h"
@@ -285,7 +286,11 @@ _destructor_ static void cleanup_pools(void) {
/* The pool is only allocated by the main thread, but the memory can
* be passed to other threads. Let's clean up if we are the main thread
* and no other threads are live. */
- if (!is_main_thread())
+ /* We build our own is_main_thread() here, which doesn't use C11
+ * TLS based caching of the result. That's because valgrind apparently
+ * doesn't like malloc() (which C11 TLS internally uses) to be called
+ * from a GCC destructors. */
+ if (getpid() != gettid())
return;
r = get_proc_field("/proc/self/status", "Threads", WHITESPACE, &t);