Commit ddffae0a authored by Dmitry Shulga's avatar Dmitry Shulga

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.
parent 54143350
......@@ -87,7 +87,9 @@ struct st_debug_sync_globals
ulonglong dsp_executed; /* statistics */
ulonglong dsp_max_active; /* statistics */
st_debug_sync_globals() : ds_signal_set(PSI_NOT_INSTRUMENTED, signal_key) {};
st_debug_sync_globals() :
ds_signal_set(PSI_NOT_INSTRUMENTED, signal_key),
dsp_hits (0), dsp_executed(0), dsp_max_active(0) {};
~st_debug_sync_globals()
{
clear_set();
......@@ -422,12 +424,24 @@ void debug_sync_end_thread(THD *thd)
}
/* Statistics. */
mysql_mutex_lock(&debug_sync_global->ds_mutex);
/*
Protect access with debug_sync_global->ds_mutex only if
it had been initialized.
*/
if (debug_sync_C_callback_ptr)
mysql_mutex_lock(&debug_sync_global->ds_mutex);
debug_sync_global->dsp_hits+= ds_control->dsp_hits;
debug_sync_global->dsp_executed+= ds_control->dsp_executed;
if (debug_sync_global->dsp_max_active < ds_control->dsp_max_active)
debug_sync_global->dsp_max_active= ds_control->dsp_max_active;
mysql_mutex_unlock(&debug_sync_global->ds_mutex);
/*
Protect access with debug_sync_global->ds_mutex only if
it had been initialized.
*/
if (debug_sync_C_callback_ptr)
mysql_mutex_unlock(&debug_sync_global->ds_mutex);
my_free(ds_control);
thd->debug_sync_control= NULL;
......
......@@ -1748,7 +1748,9 @@ THD::~THD()
lf_hash_put_pins(tdc_hash_pins);
if (xid_hash_pins)
lf_hash_put_pins(xid_hash_pins);
#if defined(ENABLED_DEBUG_SYNC)
debug_sync_end_thread(this);
#endif
/* Ensure everything is freed */
status_var.local_memory_used-= sizeof(THD);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment