mirror of
https://github.com/glest/glest-source.git
synced 2025-09-26 15:39:21 +02:00
- bugfixes related to cppcheck report
- bugfixes found using valgrind (memory leaks)
This commit is contained in:
@@ -94,29 +94,38 @@ void Thread::resume() {
|
||||
|
||||
class SDLMutexSafeWrapper {
|
||||
protected:
|
||||
SDL_mutex *mutex;
|
||||
SDL_mutex **mutex;
|
||||
bool destroyMutexInDestructor;
|
||||
|
||||
public:
|
||||
|
||||
SDLMutexSafeWrapper(SDL_mutex *mutex) {
|
||||
SDLMutexSafeWrapper(SDL_mutex **mutex, bool destroyMutexInDestructor=false) {
|
||||
this->mutex = mutex;
|
||||
this->destroyMutexInDestructor = destroyMutexInDestructor;
|
||||
Lock();
|
||||
}
|
||||
~SDLMutexSafeWrapper() {
|
||||
ReleaseLock();
|
||||
bool keepMutex = (this->destroyMutexInDestructor == true && mutex != NULL && *mutex != NULL);
|
||||
ReleaseLock(keepMutex);
|
||||
|
||||
if(this->destroyMutexInDestructor == true && mutex != NULL && *mutex != NULL) {
|
||||
SDL_DestroyMutex(*mutex);
|
||||
*mutex = NULL;
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Lock() {
|
||||
if(this->mutex != NULL) {
|
||||
SDL_mutexP(this->mutex);
|
||||
if(mutex != NULL && *mutex != NULL) {
|
||||
SDL_mutexP(*mutex);
|
||||
}
|
||||
}
|
||||
void ReleaseLock(bool keepMutex=false) {
|
||||
if(this->mutex != NULL) {
|
||||
SDL_mutexV(this->mutex);
|
||||
if(mutex != NULL && *mutex != NULL) {
|
||||
SDL_mutexV(*mutex);
|
||||
|
||||
if(keepMutex == false) {
|
||||
this->mutex = NULL;
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +133,7 @@ public:
|
||||
|
||||
Mutex::Mutex(string ownerId) {
|
||||
mutexAccessor = SDL_CreateMutex();
|
||||
SDLMutexSafeWrapper safeMutex(mutexAccessor);
|
||||
SDLMutexSafeWrapper safeMutex(&mutexAccessor);
|
||||
refCount=0;
|
||||
this->ownerId = ownerId;
|
||||
mutex = SDL_CreateMutex();
|
||||
@@ -138,7 +147,7 @@ Mutex::Mutex(string ownerId) {
|
||||
}
|
||||
|
||||
Mutex::~Mutex() {
|
||||
SDLMutexSafeWrapper safeMutex(mutexAccessor);
|
||||
SDLMutexSafeWrapper safeMutex(&mutexAccessor,true);
|
||||
if(mutex == NULL) {
|
||||
char szBuf[1024]="";
|
||||
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str());
|
||||
|
Reference in New Issue
Block a user