I have found a very interesting incident of memory leak in my code. Although I have not been able to find the root cause of the leak still thought to share with you all. I will really appreciate any help on this. I am rather curious to know how come a memory leak can be seen in use of CString in such a simple way. Code: We have a thread function:
UINT __cdecl LogWriteThread(void *pParam)
{
CLog* pLog = (CLog*)pParam;
UNUSED_ALWAYS(pParam);
try
{
pLog->LogWriteFunc();
}
.................
.................
return 0;
}
UINT __cdecl CLog::LogWriteFunc(void *pParam)
{
..........
CString cstrLogDataBuffer = m_cstrLogLine;
m_cstrLogLine = _T("");
CopyLogToFileByThread(cstrLogDataBuffer);
}
void CMpmLog::CopyLogToFileByThread(const CString& cstrLogDataBuffer)
{
....................
const long iLength = cstrLogDataBuffer.GetLength();
char *pBuffer = new char[iLength + 1];
for (long iIndex = 0;iIndex < iLength; iIndex++)
{
pBuffer[iIndex] = (char)cstrLogDataBuffer.GetAt(iIndex);
}
pBuffer[iLength] = '\0';
const unsigned int uiWriteLen = fwrite((const void \*)pBuffer, sizeof(char),iLength, m\_pofLogStream);
delete\[\] pBuffer;
....................
}
======================== If I commment call for "CopyLogToFileByThread" in function LogWriteFunc then memory leak goes away. But thats not the solution.
Manoj Never Gives up