I'm appending to a CString in a loop that is running in a child thread:
void CMyClass::MyLoop()
{
BSTR bstrMyString;
while(m_bDoLoop)
{
m_pIInterface->GetString(&bstrMyString);
CString strLocalString = bstrMyString;
m_strMemberString += strLocalString;
SysFreeString(bstrMyString);
}
}
I've been told by VS2005 that the addition assignment is causing a memory leak. I've never had this problem before...:confused:
Please someone explain what's going on? Thanks.
--- edit ---
I'm not using m_strMemberString anywhere else, apart from declaring it at the top of the CPP file as it is static. But just in case, I wrapped this bit in Enter and Leave Critical Sections, but still the same problem. Thanks for the suggestion, though.
VS2005's complaint:
Call Stack:
f:\sp\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp (173): CAfxStringMgr::Reallocate
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (866): ATL::CSimpleStringT<wchar_t,1>::Reallocate
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (855): ATL::CSimpleStringT<wchar_t,1>::PrepareWrite2
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (824): ATL::CSimpleStringT<wchar_t,1>::PrepareWrite
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (529): ATL::CSimpleStringT<wchar_t,1>::Preallocate
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (420): ATL::CSimpleStringT<wchar_t,1>::Append
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (445): ATL::CSimpleStringT<wchar_t,1>::Append
f:\sp\vctools\vc7libs\ship\atlmfc\include\atlsimpstr.h (347): ATL::CSimpleStringT<wchar_t,1>::operator+=
f:\sp\vctools\vc7libs\ship\atlmfc\include\cstringt.h (1328): ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::operator+=
c:\projects\myproj\myapp\myclass.cpp (368): CMyClass::MyLoop
f:\sp\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (109): _AfxThreadEntry
f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c (348): _callthreadstartex
f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c (331): _threadstartex
0x7C80B729 (File and line number not available): GetModuleFileNameA