提交 a1eb8cb5 编写于 作者: R Rich Felker

avoid crash on stupid but allowable usage of pthread_mutex_unlock

unlocking an unlocked mutex is not UB for robust or error-checking
mutexes, so we must avoid calling __pthread_self (which might crash
due to lack of thread-register initialization) until after checking
that the mutex is locked.
上级 620a1346
......@@ -5,9 +5,11 @@ int pthread_mutex_unlock(pthread_mutex_t *m)
pthread_t self;
if (m->_m_type != PTHREAD_MUTEX_NORMAL) {
if (!m->_m_lock)
return EPERM;
self = __pthread_self();
if ((m->_m_lock&0x1fffffff) != self->tid)
return EPERM;
return EPERM;
if ((m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE && --m->_m_count)
return 0;
if (m->_m_type >= 4) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册