Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm appending to a CString in a loop that is running in a child thread:
VB
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:
VB
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
Posted
Updated 21-Feb-10 21:16pm
v4

1 solution

Wild guess: you use m_strMemberString in the main thread too and have not synchronized the access to.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900