Bug #38240 Crash in safe_mutex_lock () thr_mutex.c line 97 on rotate_relay_log

The reason for the crash was rotate_relay_log (mi=0x0) did not verify
the passed value of active_mi.  There are more cases where active_mi
is supposed to be non-zero e.g change_master(), stop_slave(), and it's
reasonable to protect from a similar crash all of them with common
fixes.
            
Fixed with spliting end_slave() in slave threads release and slave
data clean-up parts (a new close_active_mi()). The new function is
invoked at the very end of close_connections() so that all users of
active_mi are proven to have left.

sql/mysqld.cc:
  added the 2nd part (data) of the slave's clean up.
sql/slave.cc:
  end_slave() is split in two part to release the slave threads and the remained
  resources separately.
  The new close_active_mi() should be called after all possible users ofactive_mi
  has left, i.e at the very end of close_connections().
sql/slave.h:
  interface to the new end_active_mi() function is added.
This commit is contained in:
Andrei Elkin 2009-06-23 12:10:04 +03:00
commit e2ac8c07bd
3 changed files with 23 additions and 4 deletions

View file

@ -668,7 +668,7 @@ static int end_slave_on_walk(Master_info* mi, uchar* /*unused*/)
/*
Free all resources used by slave
Release slave threads at time of executing shutdown.
SYNOPSIS
end_slave()
@ -694,14 +694,31 @@ void end_slave()
once multi-master code is ready.
*/
terminate_slave_threads(active_mi,SLAVE_FORCE_ALL);
end_master_info(active_mi);
delete active_mi;
active_mi= 0;
}
pthread_mutex_unlock(&LOCK_active_mi);
DBUG_VOID_RETURN;
}
/**
Free all resources used by slave threads at time of executing shutdown.
The routine must be called after all possible users of @c active_mi
have left.
SYNOPSIS
close_active_mi()
*/
void close_active_mi()
{
pthread_mutex_lock(&LOCK_active_mi);
if (active_mi)
{
end_master_info(active_mi);
delete active_mi;
active_mi= 0;
}
pthread_mutex_unlock(&LOCK_active_mi);
}
static bool io_slave_killed(THD* thd, Master_info* mi)
{