IFILEMGR_OpenFile crash | developer.brewmp.com IFILEMGR_OpenFile crash | developer.brewmp.com

Developer

IFILEMGR_OpenFile crash

Forums:

When I'm downloading a file, I'm putting the data downloaded into a buffer. When it finishes, the following code runs crashing on IFILEMGR_OpenFile before checking if it is NULL. The strange thing is that this, not happen all the times, from my view this crash is aleatory :confused: (obviously it is not).
If anyone can give me an idea of what could it be, I'll be grateful.

if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr) != SUCCESS){
DBGPRINTF("ERROR CREATING FILE MANAGER");
else{
IFile* pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, filename, _OFM_CREATE);
DBGPRINTF("FILE CREATED %s", filename);
if (pIFile == NULL){
DBGPRINTF("ERROR CREATING FILE %s", filename);
DBGPRINTF("ERROR %s", FileError(IFILEMGR_GetLastError(pMe->m_pIFileMgr)));
}else{
if(IFILE_Write(pIFile, buf, size) != size) {
DBGPRINTF("ERROR saving file %s", filename);
}else{
DBGPRINTF("saved OK %s", filename);
};
DBGPRINTF("IFILE RELEASE");
IFILE_Release(pIFile);
}

DBGPRINTF("IFILE MGR RELEASE");
IFILEMGR_Release(pMe->m_pIFileMgr);

Are you sure that it is crashing on IFILEMGR_OpenFile? Have you checked to make sure that filename is not NULL, since that would crash the application on the DBGPRINTF line on the next line. Surprisingly IFILEMGR_OpenFile doesn't appear to crash if passed a NULL file name (most of the BREW APIs don't check for NULL arguments), but that DBGPRINTF call would.

Are you sure that it is crashing on IFILEMGR_OpenFile? Have you checked to make sure that filename is not NULL, since that would crash the application on the DBGPRINTF line on the next line. Surprisingly IFILEMGR_OpenFile doesn't appear to crash if passed a NULL file name (most of the BREW APIs don't check for NULL arguments), but that DBGPRINTF call would.

yes it's checked because the line before the code i posted is:
DBGPRINTF("OPEN FILE %s", filename);
and it works ok... :confused:
thanks anyway for replying... :)

yes it's checked because the line before the code i posted is:
DBGPRINTF("OPEN FILE %s", filename);
and it works ok... :confused:
thanks anyway for replying... :)

This happened to me once - You may want to check to see if that file already exists....

This happened to me once - You may want to check to see if that file already exists....

Yes i'm already checking that too...
the full code when i'm saving the file is:
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr) != SUCCESS){
DBGPRINTF("ERROR CREATING FILE MANAGER");
else{
if (IFILEMGR_Test(pMe->m_pIFileMgr, filename) == SUCCESS ){
if (IFILEMGR_Remove(pMe->m_pIFileMgr, filename) == SUCCESS){
DBGPRINTF("FILE DELETED %s", filename);
}else{
DBGPRINTF("ERROR deleting file %s", filename);
res = FALSE;
}
}
DBGPRINTF("OPEN FILE %s", filename);
IFile* pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, filename, _OFM_CREATE);
DBGPRINTF("FILE CREATED %s", filename);
if (pIFile == NULL){
DBGPRINTF("ERROR CREATING FILE %s", filename);
DBGPRINTF("ERROR %s", FileError(IFILEMGR_GetLastError(pMe->m_pIFileMgr)));
}else{
if(IFILE_Write(pIFile, buf, size) != size) {
DBGPRINTF("ERROR saving file %s", filename);
}else{
DBGPRINTF("saved OK %s", filename);
};
DBGPRINTF("IFILE RELEASE");
IFILE_Release(pIFile);
}

DBGPRINTF("IFILE MGR RELEASE");
IFILEMGR_Release(pMe->m_pIFileMgr);
thank for replying... any other idea?

Yes i'm already checking that too...
the full code when i'm saving the file is:
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr) != SUCCESS){
DBGPRINTF("ERROR CREATING FILE MANAGER");
else{
if (IFILEMGR_Test(pMe->m_pIFileMgr, filename) == SUCCESS ){
if (IFILEMGR_Remove(pMe->m_pIFileMgr, filename) == SUCCESS){
DBGPRINTF("FILE DELETED %s", filename);
}else{
DBGPRINTF("ERROR deleting file %s", filename);
res = FALSE;
}
}
DBGPRINTF("OPEN FILE %s", filename);
IFile* pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, filename, _OFM_CREATE);
DBGPRINTF("FILE CREATED %s", filename);
if (pIFile == NULL){
DBGPRINTF("ERROR CREATING FILE %s", filename);
DBGPRINTF("ERROR %s", FileError(IFILEMGR_GetLastError(pMe->m_pIFileMgr)));
}else{
if(IFILE_Write(pIFile, buf, size) != size) {
DBGPRINTF("ERROR saving file %s", filename);
}else{
DBGPRINTF("saved OK %s", filename);
};
DBGPRINTF("IFILE RELEASE");
IFILE_Release(pIFile);
}

DBGPRINTF("IFILE MGR RELEASE");
IFILEMGR_Release(pMe->m_pIFileMgr);
thank for replying... any other idea?

Is this occurring on the simulator or on a handset? I am assuming on a handset, in which case you have to be careful about relying on DBGPRINTF, especially when debugging crashing bugs. On many (all?) phones, DBGPRINTF is asynchronous, so it may not actually send all of the DBGPRINTFs that were made before the phone crashed.
http://brewforums.qualcomm.com/showthread.php?t=3979
You could try the "Sync/Async DBGPRINTF" debug mode (###7) to see if it is crashing where you think it is or if it is actually crashing somewhere later on. You should be warned though that it may slow down your application quite a bit if you are using a lot of DBGPRINTFs.

Is this occurring on the simulator or on a handset? I am assuming on a handset, in which case you have to be careful about relying on DBGPRINTF, especially when debugging crashing bugs. On many (all?) phones, DBGPRINTF is asynchronous, so it may not actually send all of the DBGPRINTFs that were made before the phone crashed.
http://brewforums.qualcomm.com/showthread.php?t=3979
You could try the "Sync/Async DBGPRINTF" debug mode (###7) to see if it is crashing where you think it is or if it is actually crashing somewhere later on. You should be warned though that it may slow down your application quite a bit if you are using a lot of DBGPRINTFs.

thanx for the info, but I'm using the simulator... :(

thanx for the info, but I'm using the simulator... :(