Debug Assertion Failed on free pointer
Hi,
Currently I am using a char* pointer to point to a file.
The program goes like this:-
char* file[] = {"test1.txt", "test2.txt"};
void process()
{
char* ptr;
whie(1)
{
ptr = file[i];
parse(ptr);
free(ptr);
ptr = NULL;
remove(file[i]);
}
}
I am getting debug assertion failed error message.
It says :-
File:dbgheap.c
Line:1044
expression:_CrtIsValidHeapPointer(pUserData)
Everytime it goes to free(ptr), I get this message. How am I going to get rid of this?
Please help.
Thank You.
Re: Debug Assertion Failed on free pointer
Quote:
Originally posted by nhcheng
Hi,
Currently I am using a char* pointer to point to a file.
The program goes like this:-
char* file[] = {"test1.txt", "test2.txt"};
void process()
{
char* ptr;
whie(1)
{
ptr = file[i];
parse(ptr);
free(ptr);
ptr = NULL;
remove(file[i]);
}
}
I am getting debug assertion failed error message.
It says :-
File:dbgheap.c
Line:1044
expression:_CrtIsValidHeapPointer(pUserData)
Everytime it goes to free(ptr), I get this message. How am I going to get rid of this?
Please help.
Thank You.
where to begin....
You don't free/delete anything unless you have explicitly allocated it. And the code you posted, does not show it.
free is used with malloc
delete is used with new
Look them up on msdn.microsoft.com