mirror of
https://github.com/glest/glest-source.git
synced 2025-08-17 13:50:43 +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 )
|
int nErrorID = 0 )
|
||||||
{
|
{
|
||||||
// Build basic error string
|
// Build basic error string
|
||||||
static char acErrorBuffer[256];
|
static char acErrorBuffer[8096];
|
||||||
std::ostrstream outs(acErrorBuffer, (sizeof(acErrorBuffer) / sizeof(acErrorBuffer[0])));
|
|
||||||
outs << pcMessagePrefix << ": ";
|
outs << pcMessagePrefix << ": ";
|
||||||
|
|
||||||
// Tack appropriate canned message onto end of supplied message
|
// Tack appropriate canned message onto end of supplied message
|
||||||
@@ -218,7 +217,7 @@ Mutex UPNP_Tools::mutexUPNP;
|
|||||||
|
|
||||||
// Finish error message off and return it.
|
// Finish error message off and return it.
|
||||||
outs << std::ends;
|
outs << std::ends;
|
||||||
acErrorBuffer[(sizeof(acErrorBuffer) / sizeof(acErrorBuffer[0])) - 1] = '\0';
|
acErrorBuffer[8095] = '\0';
|
||||||
return acErrorBuffer;
|
return acErrorBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,6 +42,11 @@ Thread::~Thread() {
|
|||||||
|
|
||||||
MutexSafeWrapper safeMutex(&Thread::mutexthreadList);
|
MutexSafeWrapper safeMutex(&Thread::mutexthreadList);
|
||||||
std::vector<Thread *>::iterator iterFind = std::find(Thread::threadList.begin(),Thread::threadList.end(),this);
|
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);
|
Thread::threadList.erase(iterFind);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
@@ -428,9 +433,11 @@ void MasterSlaveThreadController::clearSlaves(bool clearListOnly) {
|
|||||||
if(clearListOnly == false) {
|
if(clearListOnly == false) {
|
||||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||||
|
if(slave != NULL) {
|
||||||
slave->setMasterController(NULL);
|
slave->setMasterController(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this->slaveThreadList.clear();
|
this->slaveThreadList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,9 +464,11 @@ void MasterSlaveThreadController::setSlaves(std::vector<SlaveThreadControllerInt
|
|||||||
if(this->slaveThreadList.empty() == false) {
|
if(this->slaveThreadList.empty() == false) {
|
||||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||||
|
if(slave != NULL) {
|
||||||
slave->setMasterController(this);
|
slave->setMasterController(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSlaveThreadController::signalSlaves(void *userdata) {
|
void MasterSlaveThreadController::signalSlaves(void *userdata) {
|
||||||
@@ -472,9 +481,11 @@ void MasterSlaveThreadController::signalSlaves(void *userdata) {
|
|||||||
if(this->slaveThreadList.empty() == false) {
|
if(this->slaveThreadList.empty() == false) {
|
||||||
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
for(unsigned int i = 0; i < this->slaveThreadList.size(); ++i) {
|
||||||
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
SlaveThreadControllerInterface *slave = this->slaveThreadList[i];
|
||||||
|
if(slave != NULL) {
|
||||||
slave->signalSlave(userdata);
|
slave->signalSlave(userdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(debugMasterSlaveThreadController) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user