mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 21:04:00 +02:00
- add a few more safety's in the code to avoid memory issues
This commit is contained in:
@@ -195,8 +195,7 @@ Mutex UPNP_Tools::mutexUPNP;
|
||||
int nErrorID = 0 )
|
||||
{
|
||||
// Build basic error string
|
||||
static char acErrorBuffer[256];
|
||||
std::ostrstream outs(acErrorBuffer, (sizeof(acErrorBuffer) / sizeof(acErrorBuffer[0])));
|
||||
static char acErrorBuffer[8096];
|
||||
outs << pcMessagePrefix << ": ";
|
||||
|
||||
// Tack appropriate canned message onto end of supplied message
|
||||
@@ -218,7 +217,7 @@ Mutex UPNP_Tools::mutexUPNP;
|
||||
|
||||
// Finish error message off and return it.
|
||||
outs << std::ends;
|
||||
acErrorBuffer[(sizeof(acErrorBuffer) / sizeof(acErrorBuffer[0])) - 1] = '\0';
|
||||
acErrorBuffer[8095] = '\0';
|
||||
return acErrorBuffer;
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,11 @@ Thread::~Thread() {
|
||||
|
||||
MutexSafeWrapper safeMutex(&Thread::mutexthreadList);
|
||||
std::vector<Thread *>::iterator iterFind = std::find(Thread::threadList.begin(),Thread::threadList.end(),this);
|
||||
if(iterFind == Thread::threadList.end()) {
|
||||
char szBuf[1024]="";
|
||||
snprintf(szBuf,1023,"In [%s::%s Line: %d] iterFind == Thread::threadList.end()",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
Thread::threadList.erase(iterFind);
|
||||
safeMutex.ReleaseLock();
|
||||
}
|
||||
@@ -428,7 +433,9 @@ void MasterSlaveThreadController::clearSlaves(bool clearListOnly) {
|
||||
if(clearListOnly == false) {
|
||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||
slave->setMasterController(NULL);
|
||||
if(slave != NULL) {
|
||||
slave->setMasterController(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
this->slaveThreadList.clear();
|
||||
@@ -457,7 +464,9 @@ void MasterSlaveThreadController::setSlaves(std::vector<SlaveThreadControllerInt
|
||||
if(this->slaveThreadList.empty() == false) {
|
||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||
slave->setMasterController(this);
|
||||
if(slave != NULL) {
|
||||
slave->setMasterController(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,7 +481,9 @@ void MasterSlaveThreadController::signalSlaves(void *userdata) {
|
||||
if(this->slaveThreadList.empty() == false) {
|
||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||
slave->signalSlave(userdata);
|
||||
if(slave != NULL) {
|
||||
slave->signalSlave(userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user