KindDragon / vld

Visual Leak Detector for Visual C++ 2008-2015
https://kinddragon.github.io/vld/
GNU Lesser General Public License v2.1
1.02k stars 314 forks source link

False positives in MFC Application and DLLs #36

Open dannyg100 opened 6 years ago

dannyg100 commented 6 years ago

I am trying to use VLD with a MFC application that uses several MFC DLLs (Visual Studio 2012, MFC 11.0). I added vld.h inclusion in the stdafx.h file (in the application only) and ran the application. In the VLD report there are a lot of assumed leaks, most of them are tracked down to a constant string assignment to a CString. All of them in DLLs code. These are obviously not real leaks. The reports look like this: MSVCR110D.dll!malloc_dbg() mfc110ud.dll!0x000007FECE75554F() mfc110ud.dll!0x000007FECE242211() mfc110ud.dll!0x000007FECE2426FA() mfc110ud.dll!0x000007FECE2427F5() mfc110ud.dll!0x000007FECE242480() mfc110ud.dll!0x000007FECE242CD9() mfc110ud.dll!0x000007FECE242C3F() mfc110ud.dll!0x000007FECE241592() mfc110ud.dll!0x000007FECE241612() mfc110ud.dll!0x000007FECE252BA4() c:\ptp_ws\ptp_unit\improc_algoptp\waferbase.cpp (342): ImProc_AlgoPTP.dll!UL_ImProcAlgoPTP::CWaferBase::SetBasePrms4Wfr() + 0x1A bytes (The last line points to our code. I went over other similar cases and tried the advises I found - load MFC symbols, for example, and explicitly link with vld.lib. Nothing removed these reports. Is there a way to get rid of these false positives?

netx123 commented 6 years ago

Don't include vld.h in stdafx.h You should only include vld.h once, and it should be in one (and only one) of your .c source files, you should add the vld.h include immediately after the stdafx.h include.

dannyg100 commented 6 years ago

This does not work. vld.h must be included before afxwin.h which is included inside the stdafx.h. There is a compilation error if it is not done this way. The only way to overcome the error is to add inclusion of vld.h at the stdafx.h top.