mirror of
https://github.com/glest/glest-source.git
synced 2025-08-27 01:44:23 +02:00
- bugfix for memory leak
This commit is contained in:
@@ -2435,21 +2435,31 @@ string getUserHome() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string safeCharPtrCopy(const char *ptr,int maxLength) {
|
string safeCharPtrCopy(const char *ptr,int maxLength) {
|
||||||
|
string result = "";
|
||||||
if(ptr == NULL) {
|
if(ptr == NULL) {
|
||||||
return "";
|
return result;
|
||||||
}
|
}
|
||||||
if(maxLength <= 0) {
|
if(maxLength <= 0) {
|
||||||
maxLength = 8096;
|
maxLength = 8096;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pBuffer = new char[maxLength+1];
|
int ptrLength = (int)strlen(ptr);
|
||||||
memset(pBuffer,0,maxLength+1);
|
if(ptrLength >= maxLength) {
|
||||||
|
char *pBuffer = new char[maxLength+1];
|
||||||
|
memset(pBuffer,0,maxLength+1);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
memcpy(pBuffer,ptr,min((int)strlen(ptr),maxLength));
|
memcpy(pBuffer,ptr,min((int)strlen(ptr),maxLength));
|
||||||
#else
|
#else
|
||||||
memcpy(pBuffer,ptr,std::min((int)strlen(ptr),maxLength));
|
memcpy(pBuffer,ptr,std::min((int)strlen(ptr),maxLength));
|
||||||
#endif
|
#endif
|
||||||
return pBuffer;
|
|
||||||
|
result = pBuffer;
|
||||||
|
delete [] pBuffer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = ptr;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user