diff --git a/Sources/Plasma/CoreLib/hsThread_Unix.cpp b/Sources/Plasma/CoreLib/hsThread_Unix.cpp index 7ac17a66..1e298282 100644 --- a/Sources/Plasma/CoreLib/hsThread_Unix.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Unix.cpp @@ -284,6 +284,7 @@ hsSemaphore::hsSemaphore(int initialValue, const char* name) } else { /* Anonymous semaphore shared between threads */ int shared = 0; // 1 if sharing between processes + fPSema = new sem_t; int status = sem_init(fPSema, shared, initialValue); hsThrowIfOSErr(status); } @@ -307,6 +308,7 @@ hsSemaphore::~hsSemaphore() } else { status = sem_destroy(fPSema); } + delete fPSema; hsThrowIfOSErr(status); #else int status = ::pthread_cond_destroy(&fPCond); @@ -321,7 +323,10 @@ bool hsSemaphore::TryWait() { #ifdef USE_SEMA int status = ::sem_trywait(fPSema); - return status != EAGAIN; + if (status != 0) { + return errno != EAGAIN; + } + return true; #else int status = ::pthread_mutex_trylock(&fPMutex); hsThrowIfOSErr(status);