+ -
当前位置:首页 → 问答吧 → new , delete导致的内存溢出问题,求专家帮忙看一下;

new , delete导致的内存溢出问题,求专家帮忙看一下;

时间:2011-12-07

来源:互联网

这段代码到底那内存溢出了?先用new,再用delete;这个理论上没什么问题呀!求专家帮忙看一下;
if (oFile.Open(m_ResultTitle,CFile::modeRead,&oEx)) // 以读文件方式 打开文件
{
const int nLength = (int)oFile.GetLength(); / 获取文件的大小长度
char* pszBuf = new char[nLength+2];
ZeroMemory(pszBuf,nLength+1); // ZeroMemory没有返回值,在pszBuf,中填充nLength+1个字节0;
oFile.Read(pszBuf,nLength);
CString m_File=pszBuf;

if(m_str2.IsEmpty())
{
if (m_File.Find(m_str1) > -1)
{
return TRUE;
}
}
else if (m_File.Find(m_str1) > -1 && m_File.Find(m_str2) > -1)
{
return TRUE;
}

oFile.Close();
delete [] pszBuf;
}

Detected memory leaks!
Dumping objects ->
e:\toolsuits\taskhis\taskhisview.cpp(339) : {2062} normal block at 0x036B6090, 19457 bytes long.
 Data: <700001 1 > 37 30 30 30 30 31 09 31 09 B7 C9 D0 C5 B6 CC D0 
e:\toolsuits\taskhis\taskhisview.cpp(339) : {2041} normal block at 0x036B1460, 19457 bytes long.
 Data: <700001 1 > 37 30 30 30 30 31 09 31 09 B7 C9 D0 C5 B6 CC D0 
e:\toolsuits\taskhis\taskhisview.cpp(339) : {2020} normal block at 0x036AC830, 19457 bytes long.
 Data: <700001 1 > 37 30 30 30 30 31 09 31 09 B7 C9 D0 C5 B6 CC D0 
e:\toolsuits\taskhis\taskhisview.cpp(339) : {1999} normal block at 0x036A7C00, 19457 bytes long.
 Data: <700001 1 > 37 30 30 30 30 31 09 31 09 B7 C9 D0 C5 B6 CC D0

作者: hnyztzh   发布时间: 2011-12-07

return 前delete

作者: hpf976149   发布时间: 2011-12-07