X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/d042a5372f22d81aca2506eeba13a6466bd905c1..13d05b593618882cfc356aef47a4a02fcb857271:/lib/base/eerror.cpp diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp index 3239ddc5..3fc38ade 100644 --- a/lib/base/eerror.cpp +++ b/lib/base/eerror.cpp @@ -12,6 +12,61 @@ AllocList *allocList; pthread_mutex_t memLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +void DumpUnfreed() +{ + AllocList::iterator i; + unsigned int totalSize = 0; + + if(!allocList) + return; + + size_t len = 1024; + char *buffer = (char*)malloc(1024); + for(i = allocList->begin(); i != allocList->end(); i++) + { + unsigned int tmp; + printf("%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n", + i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount); + totalSize += i->second.size; + char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount ); + for ( tmp=0; tmp < i->second.btcount; tmp++ ) + { + if ( bt_string[tmp] ) + { + char *beg = strchr(bt_string[tmp], '('); + if ( beg ) + { + std::string tmp1(beg+1); + int pos1=tmp1.find('+'), pos2=tmp1.find(')'); + if ( pos1 != std::string::npos && pos2 != std::string::npos ) + { + std::string tmp2(tmp1.substr(pos1,(pos2-pos1))); + tmp1.erase(pos1); + if (tmp1.length()) + { + int state; + abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state); + if (!state) + printf("%d %s%s\n", tmp, buffer,tmp2.c_str()); + else + printf("%d %s\n", tmp, bt_string[tmp]); + } + } + } + else + printf("%d %s\n", tmp, bt_string[tmp]); + } + } + free(bt_string); + printf("\n"); + } + free(buffer); + + printf("-----------------------------------------------------------\n"); + printf("Total Unfreed: %d bytes\n", totalSize); + fflush(stdout); +}; #else #include #endif