Special Thanks from the Supervisor Development Team

Apr 28, 2010 at 5:43 PM
Edited Apr 28, 2010 at 6:07 PM
Hello KindDragon, Our memory leaked at the average of 5MB per hour and we were trying to detect it for 3months, using various tools to detect the leak, tools like: GlowCode( Trial Version ), CppCheck, RunTimeCheck. We eventually fixed some of the leak, but the main leak was still there. So we made some modifications at VLD to adapt it to our code. We added two fields: time_t timeStamp; bool logged; and the default constructor blockinfo_s() :timeStamp( ::time( NULL ) ), logged( false ) { } at the structure blockinfo_s. We also created three new methods: VOID Reportleaks ( const long timeout, bool logAll = false ); void StartLog(); void StopLog(); at VisualLeakDetector class and its interfaces. extern "C" __declspec(dllexport) void VLDStartLog() { vld.StartLog(); } extern "C" __declspec(dllexport) void VLDStopLog() { vld.StopLog(); } extern "C" __declspec(dllexport) void VLDReportLeaks ( const long timeOut, bool logAll = false ) { vld.Reportleaks( timeOut, logAll ); } and modified the set up the default initialization of VLD to disabled and to report in file m_options |= (VLD_OPT_START_DISABLED | VLD_OPT_REPORT_TO_FILE); at VisualLeakDetector::VisualLeakDetector (). The reason is that only one of our nine process needed to be monitored and also because of the initial load time, what was considered a leak, which was not. Another modification was the file open option, which we used _wfopen instead of _wfopen_s because we needed to open the file now and then to check the leak report. if ( ( m_reportfile = ( FILE * )_wfopen(m_reportfilepath, L"w") ) == NULL ) { We also created a temporized thread after the initial system load to interact with the VLD, the thread executes every 5minutes and logs the total leak after 30minutes. unsigned int __stdcall LeakDetection( void *parameter ) { bool isFirst = true; int timeout = 300; long executeLogAll = 1800 + datatype::DateTime().GetSystemTime(); while( true ) { Sleep( timeout * 1000 ); if( isFirst ) { // after the initial system load VLDStartLog(); isFirst = false; continue; } if( executeLogAll <= datatype::DateTime().GetSystemTime() ) { VLDReportLeaks( timeout, true ); executeLogAll = 1800 + datatype::DateTime().GetSystemTime(); } else { VLDReportLeaks( timeout ); } } _endthreadex( 0 ); return 0; } The idea is that every memory block has a timestamp acording to the time of its alocation. That way our method ReportLeaks, called every 5minutes, verify if there is any block allocated that was not deallocated within this time and log it, then modifing logged atribute to true so that it is not logged again (performance issue). The method VOID Reportleaks ( const long timeout, bool logAll = false ); that we coded is similar to VLD's method VOID VisualLeakDetector::reportleaks (HANDLE heap). The diference is that we run through all m_heapmap instead of looking for an specific heapmap. That way we obtain every memory blocks and we can verify if there is any block in memory existing beyond it was suposed to, according to our standards. VOID VisualLeakDetector::Reportleaks ( const long timeout, bool logAll = false ) { for( heapit = m_heapmap->begin() ; heapit != m_heapmap->end() ; heapit++ ) { heapinfo = (*heapit).second; blockmap = &heapinfo->blockmap; for (blockit = blockmap->begin(); blockit != blockmap->end(); ++blockit) { // Found a block which is still in the BlockMap. We've identified a potential memory leak. block = (*blockit).first; info = (*blockit).second; if( !( info->timeStamp + timeout <= ::time( NULL ) ) ) { continue; } m_leaksfound++; totalMemoryLeaked += info->size; if( info->logged == true && logAll == false ) { continue; } leaksFoundNow++; info->logged = true; ..... With this adaptation we found the 2 major leaks, one of them being from november 2007! We would like to say a big thanks for your contribution developing this excelent and powerfull tool that being OpenSource allowed us to make the necessary modifications so that we could find the exactly leak spots. If you want the entire code with this modification to add as an option in the VLD, please give us your email that we will send the entire code. Special Thanks from the Supervisor Development Team at Autotrac( www.autotrac.com.br ) Employee Eduardo Henrique Developer/System Analysis Pablo Aranha Developer/System Analysis Augusto Martins Developer/System Analysis Rafael Quintino Developer/System Analysis Rafael Novais Developer/System Analysis Fernando Feliu Gonçalez Project Manager
Jun 18, 2010 at 4:32 AM
Hi, Interesting additions. Well actually almost exactly what I need. I would love to see these modifications integrated into the next release. Obviously I could code the parts I need but then the license might complicate my task when dealing with the managers above. However if it is integrated in the next release, then I can just use the default libs/dll and it is way easier for me to add it into our existing project without having to worry to much about licensing. KindDragon, please consider adding this changes :) Many thanks anyway for this great work.