fix ASAN+safemalloc builds

debug_sync refactoring introduced a statically instantiated object
debug_sync_global of the structure st_debug_sync_globals.
st_debug_sync_globals includes Hash_set<> which allocates memory
in the constructor. sf_malloc() calls _my_thread_var()->dbug_id
which is pthread_getspecific(THR_KEY_mysys), and THR_KEY_mysys is 0
before pthread_key_create(). pthread_getspecific(0) returns a valid
pointer, not EINVAL. And safemalloc dereferences it.

let's statically initialize THR_KEY_mysys to -1, this makes
pthread_getspecific(THR_KEY_mysys) to fail before pthread_key_create()
is called.

followup for 8885225de66
This commit is contained in:
Sergei Golubchik 2023-07-03 18:18:02 +02:00
parent af38a8b438
commit f6ecadfee8

View File

@ -23,7 +23,7 @@
#include <m_string.h>
#include <signal.h>
pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
pthread_key(struct st_my_thread_var*, THR_KEY_mysys=-1);
mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open,
THR_LOCK_lock, THR_LOCK_myisam, THR_LOCK_heap,
THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads,