MFC DLL load from Win32 App -> Memory Leaks

  • Thread starter Thread starter eman1975
  • Start date Start date
E

eman1975

Guest
I hope i'm clear to post the problem. I'm using Visual Studio 2003 SP1. The main application is a simple Win32 application that link dinamically a MFC dll. In some case when a try to execute FreeLibrary of the dll previusly loaded by LoadLibrary i get a memory leaks. For example in this code :

[FONT=Lucida Handwriting, Cursive]a=new int [100];
hmod=LoadLibrary(FILEDLL);
FreeLibrary(hmod);
delete [] a;[/FONT]

when i execute the FreeLibrary i get this memory dump:

"TestLoadFree.exe": Load"C:\.......\TestMemLeaks.dll", ....
"TestLoadFree.exe": Load"C:\WINDOWS\system32\mfc71d.dll", ....
"TestLoadFree.exe": Load"C:\WINDOWS\system32\MFC71ITA.DLL", ....

Detected memory leaks!
Dumping objects ->
{60} normal block at 0x00852C88, 400 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
"TestLoadFree.exe": Unload"C:\.......\TestMemLeaks.dll"
"TestLoadFree.exe": Unload"C:\WINDOWS\system32\mfc71d.dll"
"TestLoadFree.exe": Unload"C:\WINDOWS\system32\MFC71ITA.DLL



It seems a Fake memory leaks .. but i'm not sure.
smile_sad.gif
! So i added the ExitInstance handler of MFC dll to verify when the memory leaks is fired:

[FONT=Lucida Handwriting, Cursive]int CTestMemLeaksApp::ExitInstance()
{
TRACE(_T("Start ExitInstance() for regular DLL: TESTDLL\n"));
int retvalue=CWinApp::ExitInstance();
TRACE(_T("End ExitInstance() for regular DLL: TESTDLL\n"));
return retvalue;
}[/FONT]

and i get this memory dump:

"TestLoadFree.exe": Load"C:\.......\TestMemLeaks.dll", ....
"TestLoadFree.exe": Load"C:\WINDOWS\system32\mfc71d.dll", ....
"TestLoadFree.exe": Load"C:\WINDOWS\system32\MFC71ITA.DLL", ....

Start ExitInstance() for regular DLL: TESTDLL
End ExitInstance() for regular DLL: TESTDLL


Detected memory leaks!
Dumping objects ->
{60} normal block at 0x00852C88, 400 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
"TestLoadFree.exe": Unload"C:\.......\TestMemLeaks.dll"
"TestLoadFree.exe": Unload"C:\WINDOWS\system32\mfc71d.dll"
"TestLoadFree.exe": Unload"C:\WINDOWS\system32\MFC71ITA.DLL"

the debbugger write the memory dump when the FreeLibrary is called ...
It is clear that the memory leaks is related to a pointer allocation. But it is not clear because the memory leak is present! I suspect to some not right settings of two project... But the main application is a Win32 application with Code generation = Debug Multithreaded DLL, while the dll mfc use the same code generation setting and the MFC is used in shared mode (Use MFC in Shared DLL). I think it is all right .. but the memory leaks is again there!
smile_baringteeth.gif


If it is useful i can post the entire two project (both are near to the code generate by wizard
smile_wink.gif
)

Thank in advance!

Continue reading...
 
Back
Top