Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_CrtIsValidHeapPointer(pUserData)? 2

Status
Not open for further replies.

Zech

Programmer
Oct 14, 2002
116
US

Hi

I get the following error when trying to run my codes on my VC++ 6.0.

Debug Assertion Failed!

File:dbgheap.c
Line:1044
Expression:_CrtIsValidHeapPointer(pUserData)

Can somebody explains what it means? Thanks.

Zech
 
It seems that you try either to delete memory which has already been released or to delete memory which wasn't allocated dynamically on heap, but on stack. Eg.
Code:
void func()
{
   int i = 0;
   int* pi = &i;
   
   delete pi;   // we're deleting non-heap memory
}

Standa K.
 
or
int *x;
*x = 123;//x is not initialized

when you will look in debugger the falue of x will be probably 0xCCCCCCCC or 0xC0C0C0C0 or something like that. If x is 0 then it is a null pointer exception.
Also an error is:
int *x = new int[elements];
for(int i = 0; i <= elements; i++)
{
x = something...
//error when i will be elements;, put elements - 1
//instead of elements or < instead of <=
}
this error is often raised when working especially with arrays and strings. For example
int len = strlen(somestring);
char* acopy = new char[len];//to avoid error put there len+1
strcpy(acopy, somestrimg);//there is an error

Many of these errors you will not get when working in release mode or when just lauching the exe module. But these errors are dangerous.

Ion Filipski
1c.bmp
 
Thanks for the replies.

I finally got a hold on a loose pointer that pointed to a stack-based memory. :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top