Skip to content

Commit ddffae0

Browse files
committed
MDEV-31871: maria-install-db fails on MacOS
Follow-up to fix issue with access to probably not-initialized mutex/cond_var Constructor of the class st_debug_sync_globals was changed to initialize the data members dsp_hits, dsp_executed, dsp_max_active with zero. Formerly, these data members were filled with zeroes by C-runtime since the variable debug_sync_global was declared as static and according with C rules the static variable initialized with zero bytes. By the same reason, the data members debug_sync_global->ds_mutex debug_sync_global->ds_cond were initialized by zeros before the patch for MDEV-31871. After this patch the memory for the synch primitives debug_sync_global->ds_mutex and debug_sync_global->ds_cond are initialized explicitly by calling the functions mysql_mutex_init/mysql_cond_init so access to these synch primitives should be done only after such initialization be completed. Guarded access to these synch primitives has been added to the function debug_sync_end_thread() that is called on clean up since that was single problem place detected by MSAN. Theoretically problem places located in the function debug_sync_execute were not protected with similar check since it is not obvious that the variables debug_sync_global->ds_mutex and debug_sync_global->ds_cond could be not initilialized for use cases where the function debug_sync_execute() is called. It is required additional study to conclude whether it does need or not.
1 parent 5414335 commit ddffae0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

sql/debug_sync.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ struct st_debug_sync_globals
8787
ulonglong dsp_executed; /* statistics */
8888
ulonglong dsp_max_active; /* statistics */
8989

90-
st_debug_sync_globals() : ds_signal_set(PSI_NOT_INSTRUMENTED, signal_key) {};
90+
st_debug_sync_globals() :
91+
ds_signal_set(PSI_NOT_INSTRUMENTED, signal_key),
92+
dsp_hits (0), dsp_executed(0), dsp_max_active(0) {};
9193
~st_debug_sync_globals()
9294
{
9395
clear_set();
@@ -422,12 +424,24 @@ void debug_sync_end_thread(THD *thd)
422424
}
423425

424426
/* Statistics. */
425-
mysql_mutex_lock(&debug_sync_global->ds_mutex);
427+
/*
428+
Protect access with debug_sync_global->ds_mutex only if
429+
it had been initialized.
430+
*/
431+
if (debug_sync_C_callback_ptr)
432+
mysql_mutex_lock(&debug_sync_global->ds_mutex);
433+
426434
debug_sync_global->dsp_hits+= ds_control->dsp_hits;
427435
debug_sync_global->dsp_executed+= ds_control->dsp_executed;
428436
if (debug_sync_global->dsp_max_active < ds_control->dsp_max_active)
429437
debug_sync_global->dsp_max_active= ds_control->dsp_max_active;
430-
mysql_mutex_unlock(&debug_sync_global->ds_mutex);
438+
439+
/*
440+
Protect access with debug_sync_global->ds_mutex only if
441+
it had been initialized.
442+
*/
443+
if (debug_sync_C_callback_ptr)
444+
mysql_mutex_unlock(&debug_sync_global->ds_mutex);
431445

432446
my_free(ds_control);
433447
thd->debug_sync_control= NULL;

sql/sql_class.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,9 @@ THD::~THD()
17481748
lf_hash_put_pins(tdc_hash_pins);
17491749
if (xid_hash_pins)
17501750
lf_hash_put_pins(xid_hash_pins);
1751+
#if defined(ENABLED_DEBUG_SYNC)
17511752
debug_sync_end_thread(this);
1753+
#endif
17521754
/* Ensure everything is freed */
17531755
status_var.local_memory_used-= sizeof(THD);
17541756

0 commit comments

Comments
 (0)