mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 11:24:00 +02:00
- memory leak checker fixed a few issues
This commit is contained in:
@@ -68,89 +68,91 @@ void exceptionMessage(const exception &excp) {
|
|||||||
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||||
static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
|
static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
|
||||||
int line=-1;
|
int line=-1;
|
||||||
const int maxbufSize = 8094;
|
if(PlatformExceptionHandler::application_binary != "") {
|
||||||
char buf[maxbufSize+1]="";
|
const int maxbufSize = 8094;
|
||||||
//char *p=NULL;
|
char buf[maxbufSize+1]="";
|
||||||
|
//char *p=NULL;
|
||||||
|
|
||||||
// prepare command to be executed
|
// prepare command to be executed
|
||||||
// our program need to be passed after the -e parameter
|
// our program need to be passed after the -e parameter
|
||||||
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
|
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
|
||||||
sprintf(buf, "addr2line -C -e %s -f -i %p",PlatformExceptionHandler::application_binary.c_str(),address);
|
sprintf(buf, "addr2line -C -e %s -f -i %p",PlatformExceptionHandler::application_binary.c_str(),address);
|
||||||
|
|
||||||
FILE* f = popen (buf, "r");
|
FILE* f = popen (buf, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
perror (buf);
|
perror (buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(function != NULL && function[0] != '\0') {
|
if(function != NULL && function[0] != '\0') {
|
||||||
line = 0;
|
line = 0;
|
||||||
for(;function != NULL && function[0] != '\0';) {
|
for(;function != NULL && function[0] != '\0';) {
|
||||||
// get function name
|
// get function name
|
||||||
char *ret = fgets (buf, maxbufSize, f);
|
char *ret = fgets (buf, maxbufSize, f);
|
||||||
if(ret == NULL) {
|
if(ret == NULL) {
|
||||||
pclose(f);
|
pclose(f);
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
//printf("Looking for [%s] Found [%s]\n",function,ret);
|
//printf("Looking for [%s] Found [%s]\n",function,ret);
|
||||||
if(strstr(ret,function) != NULL) {
|
if(strstr(ret,function) != NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// get file and line
|
|
||||||
ret = fgets (buf, maxbufSize, f);
|
|
||||||
if(ret == NULL) {
|
|
||||||
pclose(f);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strlen(buf) > 0 && buf[0] != '?') {
|
|
||||||
//int l;
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
// file name is until ':'
|
|
||||||
while(*p != 0 && *p != ':') {
|
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = 0;
|
// get file and line
|
||||||
// after file name follows line number
|
ret = fgets (buf, maxbufSize, f);
|
||||||
strcpy (file , buf);
|
if(ret == NULL) {
|
||||||
sscanf (p,"%d", &line);
|
pclose(f);
|
||||||
}
|
return line;
|
||||||
else {
|
}
|
||||||
strcpy (file,"unknown");
|
|
||||||
line = 0;
|
if(strlen(buf) > 0 && buf[0] != '?') {
|
||||||
|
//int l;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
// file name is until ':'
|
||||||
|
while(*p != 0 && *p != ':') {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p++ = 0;
|
||||||
|
// after file name follows line number
|
||||||
|
strcpy (file , buf);
|
||||||
|
sscanf (p,"%d", &line);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strcpy (file,"unknown");
|
||||||
|
line = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// get file and line
|
// get file and line
|
||||||
char *ret = fgets (buf, maxbufSize, f);
|
char *ret = fgets (buf, maxbufSize, f);
|
||||||
if(ret == NULL) {
|
if(ret == NULL) {
|
||||||
|
pclose(f);
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strlen(buf) > 0 && buf[0] != '?') {
|
||||||
|
//int l;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
// file name is until ':'
|
||||||
|
while(*p != 0 && *p != ':') {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p++ = 0;
|
||||||
|
// after file name follows line number
|
||||||
|
strcpy (file , buf);
|
||||||
|
sscanf (p,"%d", &line);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strcpy (file,"unknown");
|
||||||
|
line = 0;
|
||||||
|
}
|
||||||
pclose(f);
|
pclose(f);
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strlen(buf) > 0 && buf[0] != '?') {
|
|
||||||
//int l;
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
// file name is until ':'
|
|
||||||
while(*p != 0 && *p != ':') {
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*p++ = 0;
|
|
||||||
// after file name follows line number
|
|
||||||
strcpy (file , buf);
|
|
||||||
sscanf (p,"%d", &line);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
strcpy (file,"unknown");
|
|
||||||
line = 0;
|
|
||||||
}
|
|
||||||
pclose(f);
|
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
using Shared::Platform::MutexSafeWrapper;
|
using Shared::Platform::MutexSafeWrapper;
|
||||||
|
|
||||||
bool AllocInfo::application_binary_initialized = false;
|
bool AllocInfo::application_binary_initialized = false;
|
||||||
static AllocRegistry memoryLeaks = AllocRegistry::getInstance();
|
//static AllocRegistry memoryLeaks = AllocRegistry::getInstance();
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class AllocRegistry
|
// class AllocRegistry
|
||||||
@@ -108,6 +108,11 @@ void AllocRegistry::dump(const char *path) {
|
|||||||
fprintf(f, "Not monitored allocations: %d, %lu bytes\n", nonMonitoredCount, nonMonitoredBytes);
|
fprintf(f, "Not monitored allocations: %d, %lu bytes\n", nonMonitoredCount, nonMonitoredBytes);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
printf("Memory leak dump summary:\n");
|
||||||
|
printf("Total leaks: %d, %lu bytes\n", leakCount, leakBytes);
|
||||||
|
printf("Total allocations: %d, %lu bytes\n", allocCount, allocBytes);
|
||||||
|
printf("Not monitored allocations: %d, %lu bytes\n", nonMonitoredCount, nonMonitoredBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user