Do not access mutex memory after unlock.

PR:	237195
Reported by:	freebsd@hurrikhan.eu
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2019-04-12 17:27:19 +00:00
parent 28ce2bc1b5
commit b8f75b175c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346158

View File

@ -949,7 +949,7 @@ mutex_unlock_common(struct pthread_mutex *m, bool cv, int *mtx_defer)
{
struct pthread *curthread;
uint32_t id;
int deferred, error, robust;
int deferred, error, private, robust;
if (__predict_false(m <= THR_MUTEX_DESTROYED)) {
if (m == THR_MUTEX_DESTROYED)
@ -967,6 +967,7 @@ mutex_unlock_common(struct pthread_mutex *m, bool cv, int *mtx_defer)
return (EPERM);
error = 0;
private = (m->m_flags & PMUTEX_FLAG_PRIVATE) != 0;
if (__predict_false(PMUTEX_TYPE(m->m_flags) ==
PTHREAD_MUTEX_RECURSIVE && m->m_count > 0)) {
m->m_count--;
@ -991,7 +992,7 @@ mutex_unlock_common(struct pthread_mutex *m, bool cv, int *mtx_defer)
if (robust)
_mutex_leave_robust(curthread, m);
}
if (!cv && m->m_flags & PMUTEX_FLAG_PRIVATE)
if (!cv && private)
THR_CRITICAL_LEAVE(curthread);
return (error);
}