From cb8ba63e65da87cc02371d79445f9b2aa50bc991 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 27 Sep 2016 18:14:02 +0300 Subject: Add missing checks into mutex.c --- src/common/mutex.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/common') diff --git a/src/common/mutex.c b/src/common/mutex.c index bdc2fb4dc..464a54161 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -24,6 +24,7 @@ #include "common/cbasetypes.h" // for WIN32 #include "common/memmgr.h" +#include "common/nullpo.h" #include "common/showmsg.h" #include "common/timer.h" @@ -84,6 +85,7 @@ struct mutex_data *mutex_create(void) /// @copydoc mutex_interface::destroy() void mutex_destroy(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 DeleteCriticalSection(&m->hMutex); #else @@ -96,6 +98,7 @@ void mutex_destroy(struct mutex_data *m) /// @copydoc mutex_interface::lock() void mutex_lock(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 EnterCriticalSection(&m->hMutex); #else @@ -106,6 +109,7 @@ void mutex_lock(struct mutex_data *m) /// @copydoc mutex_interface::trylock() bool mutex_trylock(struct mutex_data *m) { + nullpo_retr(false, m); #ifdef WIN32 if (TryEnterCriticalSection(&m->hMutex) != FALSE) return true; @@ -119,6 +123,7 @@ bool mutex_trylock(struct mutex_data *m) /// @copydoc mutex_interface::unlock() void mutex_unlock(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 LeaveCriticalSection(&m->hMutex); #else @@ -152,6 +157,7 @@ struct cond_data *cond_create(void) /// @copydoc mutex_interface::cond_destroy() void cond_destroy(struct cond_data *c) { + nullpo_retv(c); #ifdef WIN32 CloseHandle(c->events[EVENT_COND_SIGNAL]); CloseHandle(c->events[EVENT_COND_BROADCAST]); @@ -171,6 +177,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks) int result; bool is_last = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); c->nWaiters++; LeaveCriticalSection(&c->waiters_lock); @@ -201,6 +208,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks) mutex->lock(m); #else + nullpo_retv(m); if (timeout_ticks < 0) { pthread_cond_wait(&c->hCond, &m->hMutex); } else { @@ -221,6 +229,7 @@ void cond_signal(struct cond_data *c) #ifdef WIN32 # if 0 bool has_waiters = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); if(c->nWaiters > 0) has_waiters = true; @@ -230,6 +239,7 @@ void cond_signal(struct cond_data *c) # endif // 0 SetEvent(c->events[EVENT_COND_SIGNAL]); #else + nullpo_retv(c); pthread_cond_signal(&c->hCond); #endif } @@ -240,6 +250,7 @@ void cond_broadcast(struct cond_data *c) #ifdef WIN32 # if 0 bool has_waiters = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); if(c->nWaiters > 0) has_waiters = true; @@ -249,6 +260,7 @@ void cond_broadcast(struct cond_data *c) # endif // 0 SetEvent(c->events[EVENT_COND_BROADCAST]); #else + nullpo_retv(c); pthread_cond_broadcast(&c->hCond); #endif } -- cgit v1.2.3-70-g09d2