Commit c4f5908a authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fixed crashes found by application verifier:

- leaking mutex in lf_hash_destroy
- pthread_getspecific() before pthread_key_create() in my_thread_var_dbug()
(called by static C++ object constructors called in sys_vars)
- perfschema destroys mutexes that were  not created.
parent 970bc8cd
...@@ -335,18 +335,18 @@ void lf_hash_destroy(LF_HASH *hash) ...@@ -335,18 +335,18 @@ void lf_hash_destroy(LF_HASH *hash)
{ {
LF_SLIST *el, **head= (LF_SLIST **)_lf_dynarray_value(&hash->array, 0); LF_SLIST *el, **head= (LF_SLIST **)_lf_dynarray_value(&hash->array, 0);
if (unlikely(!head)) if (head)
return;
el= *head;
while (el)
{ {
intptr next= el->link; el= *head;
if (el->hashnr & 1) while (el)
lf_alloc_direct_free(&hash->alloc, el); /* normal node */ {
else intptr next= el->link;
my_free(el); /* dummy node */ if (el->hashnr & 1)
el= (LF_SLIST *)next; lf_alloc_direct_free(&hash->alloc, el); /* normal node */
else
my_free(el); /* dummy node */
el= (LF_SLIST *)next;
}
} }
lf_alloc_destroy(&hash->alloc); lf_alloc_destroy(&hash->alloc);
lf_dynarray_destroy(&hash->array); lf_dynarray_destroy(&hash->array);
......
...@@ -228,7 +228,6 @@ void my_thread_global_end(void) ...@@ -228,7 +228,6 @@ void my_thread_global_end(void)
} }
mysql_mutex_unlock(&THR_LOCK_threads); mysql_mutex_unlock(&THR_LOCK_threads);
pthread_key_delete(THR_KEY_mysys);
mysql_mutex_destroy(&THR_LOCK_malloc); mysql_mutex_destroy(&THR_LOCK_malloc);
mysql_mutex_destroy(&THR_LOCK_open); mysql_mutex_destroy(&THR_LOCK_open);
mysql_mutex_destroy(&THR_LOCK_lock); mysql_mutex_destroy(&THR_LOCK_lock);
...@@ -246,7 +245,7 @@ void my_thread_global_end(void) ...@@ -246,7 +245,7 @@ void my_thread_global_end(void)
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
mysql_mutex_destroy(&LOCK_localtime_r); mysql_mutex_destroy(&LOCK_localtime_r);
#endif #endif
pthread_key_delete(THR_KEY_mysys);
my_thread_global_init_done= 0; my_thread_global_init_done= 0;
} }
...@@ -429,8 +428,10 @@ const char *my_thread_name(void) ...@@ -429,8 +428,10 @@ const char *my_thread_name(void)
extern void **my_thread_var_dbug() extern void **my_thread_var_dbug()
{ {
struct st_my_thread_var *tmp= struct st_my_thread_var *tmp;
my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); if (!my_thread_global_init_done)
return NULL;
tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
return tmp && tmp->init ? &tmp->dbug : 0; return tmp && tmp->init ? &tmp->dbug : 0;
} }
#endif /* DBUG_OFF */ #endif /* DBUG_OFF */
...@@ -439,8 +440,10 @@ extern void **my_thread_var_dbug() ...@@ -439,8 +440,10 @@ extern void **my_thread_var_dbug()
safe_mutex_t **my_thread_var_mutex_in_use() safe_mutex_t **my_thread_var_mutex_in_use()
{ {
struct st_my_thread_var *tmp= struct st_my_thread_var *tmp;
my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); if (!my_thread_global_init_done)
return NULL;
tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
return tmp ? &tmp->mutex_in_use : 0; return tmp ? &tmp->mutex_in_use : 0;
} }
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
operation. operation.
*/ */
my_atomic_rwlock_t PFS_atomic::m_rwlock_array[256]; my_atomic_rwlock_t PFS_atomic::m_rwlock_array[256];
static int init_done;
void PFS_atomic::init(void) void PFS_atomic::init(void)
{ {
...@@ -68,12 +69,14 @@ void PFS_atomic::init(void) ...@@ -68,12 +69,14 @@ void PFS_atomic::init(void)
for (i=0; i< array_elements(m_rwlock_array); i++) for (i=0; i< array_elements(m_rwlock_array); i++)
my_atomic_rwlock_init(&m_rwlock_array[i]); my_atomic_rwlock_init(&m_rwlock_array[i]);
init_done= 1;
} }
void PFS_atomic::cleanup(void) void PFS_atomic::cleanup(void)
{ {
uint i; uint i;
if (!init_done)
return;
for (i=0; i< array_elements(m_rwlock_array); i++) for (i=0; i< array_elements(m_rwlock_array); i++)
my_atomic_rwlock_destroy(&m_rwlock_array[i]); my_atomic_rwlock_destroy(&m_rwlock_array[i]);
} }
......
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