theclay
asked on
CString memory leak in cwinthread
When running my code I get this:
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {86} normal block at 0x00302DF0, 31 bytes long.
Data: < Dude> 01 00 00 00 12 00 00 00 12 00 00 00 44 75 64 65
Object dump complete.
This is the code:
CString sD;
sD = "Dude this is weird";
If I comment out the second line only, the memory leak goes away.
This code is within a CWinThread object that is called from the main window and exits with a call to AfxEndThread(0); after sending a message back to the parent. I can put this code in the parent window and it's fine.
There's another instance within the CWinThread object prior to these lines where this code is run:
CFtpConnection* pCon = NULL;
try
{
pCon = parent->m_sSession->GetFtp Connection (FTP_SERVE R, FTP_USER, FTP_PW, 21, TRUE);
}
catch (CInternetException* pEx)
{
CString sConnectionErrorMsg;
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
sConnectionErrorMsg.Format ("Return error message: %s", sz);
returnCode = UPDATE_CONNECTION_ERROR;
m_sLog += "\r\nFTP connection failed\r\n" + sConnectionErrorMsg;
pEx->Delete();
delete pCon;
pCon = NULL;
}
Notice the use of CString object sConnectionErrorMsg here. This does NOT create a memory leak.
Any ideas?
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {86} normal block at 0x00302DF0, 31 bytes long.
Data: < Dude> 01 00 00 00 12 00 00 00 12 00 00 00 44 75 64 65
Object dump complete.
This is the code:
CString sD;
sD = "Dude this is weird";
If I comment out the second line only, the memory leak goes away.
This code is within a CWinThread object that is called from the main window and exits with a call to AfxEndThread(0); after sending a message back to the parent. I can put this code in the parent window and it's fine.
There's another instance within the CWinThread object prior to these lines where this code is run:
CFtpConnection* pCon = NULL;
try
{
pCon = parent->m_sSession->GetFtp
}
catch (CInternetException* pEx)
{
CString sConnectionErrorMsg;
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
sConnectionErrorMsg.Format
returnCode = UPDATE_CONNECTION_ERROR;
m_sLog += "\r\nFTP connection failed\r\n" + sConnectionErrorMsg;
pEx->Delete();
delete pCon;
pCon = NULL;
}
Notice the use of CString object sConnectionErrorMsg here. This does NOT create a memory leak.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That took care of it - thanks.
Sara