目前正在處理一些在Win XP和Win 7上調試Env的代碼。但是它在與堆損壞相關的版本中失敗了。非常感謝您的幫助。新字符後堆損壞[strlen
char *strr = NULL;
if (SomeValue!= NULL)
{
while(SomePos != NULL)
{
CString strTemp; double SomeAmount;
strTemp.Format("%f",SomeAmount);
strr = new char[strlen((LPCTSTR)strTemp + 1)];
strcpy(strr,LPCTSTR(strTemp));
if(strr)
{
strr = NULL;
delete[] strr;
}
}
}
看這個我可以找出我缺少一些東西在刪除字符指針。
您應該在nulling strr之前刪除。 – Moberg
除了添加bug之外,在刪除它之前將'strr'設置爲'NULL'會給你一個內存泄漏。可以刪除一個空指針,所以你不需要測試。 – molbdnilo