diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 673b6c1d4bc..362463a7f22 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -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; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a4aea9775bc..884d6c81511 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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);