From 5a634a8d0a1d853fc9905bc7b8908895f147322a Mon Sep 17 00:00:00 2001 From: Carl Shapiro Date: Wed, 27 Aug 2025 16:48:40 -0700 Subject: [PATCH] Always use pthread_equal to compare thread IDs This change replaces direct comparisons of Pthread thread IDs with calls to pthread_equal. Directly comparing thread IDs is neither portable nor reliable since a thread ID is defined as an opaque type that can be implemented using a structure. --- src/jemalloc.c | 3 ++- src/tsd.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/jemalloc.c b/src/jemalloc.c index 0fe69a1e..5c77621c 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -220,7 +220,8 @@ static uint8_t malloc_slow_flags; /* Used to let the initializing thread recursively allocate. */ # define NO_INITIALIZER ((unsigned long)0) # define INITIALIZER pthread_self() -# define IS_INITIALIZER (malloc_initializer == pthread_self()) +# define IS_INITIALIZER \ + (pthread_equal(malloc_initializer, pthread_self())) static pthread_t malloc_initializer = NO_INITIALIZER; #else # define NO_INITIALIZER false diff --git a/src/tsd.c b/src/tsd.c index 20042c2d..30acad93 100644 --- a/src/tsd.c +++ b/src/tsd.c @@ -528,7 +528,7 @@ tsd_init_check_recursion(tsd_init_head_t *head, tsd_init_block_t *block) { /* Check whether this thread has already inserted into the list. */ malloc_mutex_lock(TSDN_NULL, &head->lock); ql_foreach (iter, &head->blocks, link) { - if (iter->thread == self) { + if (pthread_equal(iter->thread, self)) { malloc_mutex_unlock(TSDN_NULL, &head->lock); return iter->data; }