Bug #42454 Check return value of pthread_mutex_lock
Submitted: 29 Jan 2009 14:06 Modified: 30 Jan 2009 11:03
Reporter: Jørgen Austvik Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S4 (Feature request)
Version:5.0-bzr, 5.1-bzr, 6.0-bzr OS:Any
Assigned to: CPU Architecture:Any

[29 Jan 2009 14:06] Jørgen Austvik
Description:
Lots of places in the MySQL source code, we call pthread_mutex_lock(3C) without checking the return value for an error condition. Examples: 

my_open.c:
      pthread_mutex_lock(&THR_LOCK_open);

my_pthread.h:
#define thread_safe_increment(V,L) \
        (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
#define thread_safe_decrement(V,L) \
        (pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L)))

pthread_mutex_lock() can fail with at least five different errors, if one of these happens, the call returns and the code will continue to run (thinking it has the mutex) even though the mutex is not locked.

How to repeat:
Use the source, Luke.

Suggested fix:
Check return value of pthread_mutex_lock(3C) with friends.
[30 Jan 2009 11:03] Valeriy Kravchuk
Verified by code review.