Error: _CrtIsValidHeapPointer(pUserData)
-
Hi,guys: I got a serious error when developing a DLL for my teammates' DELPHI application. Any help is appreciated. Environment: Windows2000 AS, VC++6.0SP5. Related code: typedef struct _tag_MyPackage { int len; char *data; }MyPackage; When I got some data, MyPackage *mp = new MyPackage; mp->data = new char[length of the data] memcpy(mp->data, ...); EnterCriticalSection(&m_cs); mylist.pushback(mp); LeaveCriticalSection(&m_cs); When something happens, below code is executed in another thread, EnterCriticalSection(&m_cs); iterator = mylist.begin(); MyPackage *mp = *iterator; memcpy(A_Pointer_Defined_Before, mp->data, mp->len); if (mp != NULL && mp->data != NULL) { delete [](mp->data); delete mp; } mylist.erase(iterator); LeaveCriticalSection(&m_cs); return; My program runs prefectly in much time, but, in some condition it fails at this line. delete [](mp->data); The error message: Program:\work\myapp\test.exe File: dbgheap.c Line:1044 Expression: _CrtIsValidHeapPointer(pUserData) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) And I also found it fails only when the length of data is a bit long, say, 220000bytes. Some other short length such as 100bytes/1000bytes/50000bytes are all successfully performed. Thanks for your patience and any replies.