Hello All,


I develop MFC Extension DLL and I have an problem with Memory leaks issue. I try
to use the The User-Mode Dump Heap (UMDH) tool, Umdh.exe that come with Microsoft debugging tools

After I used umdh.exe to checked the Heap I found this

#1


+ 419737 ( 875104 - 455367) 30099 allocs BackTrace3379
+ 14439 ( 30099 - 15660) BackTrace3379 allocations

ntdll!RtlpNtMakeTemporaryKey+000074CE
ntdll!LdrAlternateResourcesEnabled+00002B05
ntdll!RtlDosSearchPath_Ustr+00000310
MSVCR90!malloc+00000079
mfc90!???+00000000 : 78637550
mfc90!???+00000000 : 7862F967
mfc90!???+00000000 : 7862FA1E
mfc90!???+00000000 : 7862FA75
mfc90!???+00000000 : 7862F704
mfc90!???+00000000 : 7862F636
mfc90!???+00000000 : 7862F650
mfc90!???+00000000 : 7862F66C
mfc90!???+00000000 : 786350AD
MyDLL!CParser::ParseRecord3+00000A7C (x:\projects\folder\branchs\folder2008\folder2008_newway\source\Parser.cpp, 333)


and I look into the line of code and found this


p_RecordSummaryImp->OperValue = (*iter).GetFormattedValue().c_str();



the full code is look something like below

for (VDetail::const_iterator iter = (*pfo).begin(); iter!=iterEnd; ++iter)
{

p_RecordSummaryImp->OperValue = (*iter).GetFormattedValue().c_str();


}


and (*iter).GetFormattedValue() will return the std::string type
and p_RecordSummaryImp->OperValue, the OperValue is a CString type.

My question is Why the c_str() cause the memory leaks? and how to fix it. All suggestion are welcome



-----------------------------------------------------------------------------------------------------------
#2
the stack that got from umdh.exe :

+ 433200 ( 902580 - 469380) 30086 allocs BackTrace336F
+ 14440 ( 30086 - 15646) BackTrace336F allocations

ntdll!RtlpNtMakeTemporaryKey+000074CE
ntdll!LdrAlternateResourcesEnabled+00002B05
ntdll!RtlDosSearchPath_Ustr+00000310
MSVCR90!malloc+00000079
mfc90!???+00000000 : 78637550
mfc90!???+00000000 : 7862F967
mfc90!???+00000000 : 7862FA1E
mfc90!???+00000000 : 7862FA75
mfc90!???+00000000 : 7862F704
mfc90!???+00000000 : 7862F636
mfc90!???+00000000 : 7862F650
mfc90!???+00000000 : 7862F66C
MyDLL!CParser::ParseRecord3+00000A7C (x:\projects\folder\branchs\folder2008\folder2008_newway\source\Parser.cpp, 287)

and look at the line 287, I found this code

p_RecordSummaryImp->OPort = atoi(PPacket->szSrcPort);

p_RecordSummaryImp->OPort is a int type and the PPacket->szSrcPort is TCHAR szSrcPort[64]; and PPacket is a structure type.

Why the line is cause the memory leaks problem ? or I misunderstand about the umdh.exe result that I got above. All suggestion are welcome



Thanks for your help.
Sirichai