-
January 19th, 2004, 10:17 PM
#1
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 :-
Filebgheap.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.
-
January 19th, 2004, 10:41 PM
#2
Re: Debug Assertion Failed on free pointer
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 bgheap.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
-
January 19th, 2004, 11:08 PM
#3
hi,
Actually my main concern is to remove the files from my disk once the parsing process is done.
I thought I have to free the pointer which is pointing to the files before remove the files.
What I encounter is that although I use remove(file); the file is still in my disk. I tried to delete it manually but access denied as the file is being used. So I was suspecting it is because of the char* pointer.
Do you have any suggestion to remove the files permanently?
Thank You.
-
January 19th, 2004, 11:11 PM
#4
 
Originally posted by nhcheng
hi,
Actually my main concern is to remove the files from my disk once the parsing process is done.
I thought I have to free the pointer which is pointing to the files before remove the files.
What I encounter is that although I use remove(file); the file is still in my disk. I tried to delete it manually but access denied as the file is being used. So I was suspecting it is because of the char* pointer.
Do you have any suggestion to remove the files permanently?
Thank You.
To delete a file in a directory, I think this question iわs answered not quite long ago right on this VC++ forum, if you dont care to do a search though...
Regards,
homestead
-
January 19th, 2004, 11:18 PM
#5
How are you removing the files? How are you opening the files? There are a number of API's to delete files such as:
DeleteFile(...) WIN32
OpenFile(...) WIN32 (passing delete of course) (also a depreciated function)
remove(...) CRT
etc...
if there is an exclusive lock on the file, then you will not be able to remove it until that process/thread whatever have you closes the handle on the file.
-
January 19th, 2004, 11:21 PM
#6
Here the code
PHP Code:
BOOL DeleteFile(const char*_strRootDirectory,const char* _filename)
{
bool bSubdirectory = false;
HANDLE hFile;
string strFilePath;
string strPattern;
WIN32_FIND_DATA FileInformation;
string strRootDirectory=_strRootDirectory;
strPattern = strRootDirectory + "\\*.*";
hFile = FindFirstFile(strPattern.c_str(), &FileInformation);
FindNextFile(hFile, &FileInformation);
if(hFile != INVALID_HANDLE_VALUE)
{
while(FindNextFile(hFile, &FileInformation))
{
if(strstr(FileInformation.cFileName,_filename))
{
sprintf(m_chFileName,"%s%s%s",strRootDirectory.c_str (),"\\",FileInformation.cFileName);
:eleteFile(m_chFileName);
}
if(!strstr(FileInformation.cFileName ,"."))
{
strPattern=strRootDirectory+"\\"+FileInformation.cFileName;
DeleteFile(strPattern.c_str (),_filename);
}
}
}
return 0;
}
Mick, Mick !!!!!!!! No matter how you are....
I win this time, admit it or not...
Regards,
Fiona
-
January 19th, 2004, 11:26 PM
#7
Since I am in an excitement, I have not checked that code snip, but I think you can do it yourself right ?
Hope that helps
// By the way, that code snip is actually from a member on this board who used to give me when iwas searching for a a file in directory... That guy really had a nice intention
Regards,
homestead
-
January 19th, 2004, 11:28 PM
#8
Re: Here the code
Originally posted by Homestead
[
Mick, Mick !!!!!!!! No matter how you are....
I win this time, admit it or not...
Regards,
Fiona
he already knows the filenames, so findfirstfile would be extraneous.
-
January 19th, 2004, 11:38 PM
#9
I think it is probably caused by not closing the file handle, like fclose(), before using remove().
The return value of remove() reveals the status of the operation. If removing the file is successful, the return value is 0. Otherwise it is -1 and errno is set either to EACCES to indicate that the path specifies a read-only file, or to ENOENT to indicate that the filename or path was not found or that the path specifies a directory.
Last edited by Kheun; January 19th, 2004 at 11:41 PM.
-
January 19th, 2004, 11:41 PM
#10
Thanks everyone.
I think my application is holding the file, that's why I can't delete it.
My program looks something like this:-
char* file[] = {"test1.txt"};
void process()
{
TestRecord* parser;
RecordtoTestRecord* record;
char* ptr;
ptr = file[1];
if(parser!=NULL)
{
delete parser;
parser = NULL;
}
while(1)
{
parser = new TestRecord;
record = parser->parsefile(ptr);
record->processBlockinfile();
:
:
free(ptr); //probably I don't need to free this pointer
remove(file[1]);
}
}
I am not sure who is holding the file[1].
I thought the *parser has already pass all the data to record.
-
January 19th, 2004, 11:45 PM
#11
where do you open the file? close the handle returned from whatever open API you are using.
-
January 20th, 2004, 12:02 AM
#12
is the ptr a handler?
i try to free it but i got debug assertion error.
-
January 20th, 2004, 12:03 AM
#13
I fopen and fclose the file before i called that process().
before the process() begin, i still manage to remove(file);
but right after the parser->parsefile(ptr); i couldn't remove the file anymore.
-
January 20th, 2004, 12:17 AM
#14
probably because your filename is invalid.
what exactly are you trying to do? Your file operations are pointing to the 1 index in test.txt, which is 'e' are you trying to create a file called 'e' or test.txt?
char file [] = {"test.txt"};
...
...
...
remove(file);
-
January 20th, 2004, 12:24 AM
#15
If possible, can you post your remove function, I just wonder how you made it, there might be some error in it...
Regards,
Fiona
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|