修复windows dll中的内存泄漏

时间:2012-10-18 22:32:36

标签: c++ string dll mfc

继承了一些看起来像c ++或.Net的代码?这不在我的驾驶室里。无论如何,它通过使用堆内存然后一遍又一遍地重新分配本地内存来进行内存泄漏:

CPTRecord* pRec = static_cast<CPTRecord*>(pData);

// Remove channel # from end of test name
CString testName = pRec->m_stdf.test_txt;

int strIndex = testName.ReverseFind(' ');
if (strIndex != -1)
{
    testName.Delete(strIndex,9);
    pRec->m_stdf.test_txt = (char *)LPCTSTR(testName);
    pRec->m_stdf.test_txt_size = testName.GetLength();
}

我不确定如何投射指针,或使用memcpy而不是使用(char *)LPCTSTR分配

0 个答案:

没有答案
相关问题