Common reasons for Application Crash in BREW

The most common and fatal issue in BREW Applicaion is crashes. When you get a Application crash you are almost certain that you are accessing a invalid pointer. It means you are either using a NULL pointer are a pointer which is already free'd. In both these cases it will cause the application to crash. You can easily check the statement causing the crash using the Visual Studio IDE and check the call stack if needed. These are the most common reasons for such crashes.

1. Calling a BREW API with a invalid interface pointer.

E.g. ITAPI_MakeVoiceCall(pITAPI, pApp->szPhoneNumber, 0);

The above API will crash if the pITAPI is not created previously or a invalid pointer.

2. Double Free problem.

Sometimes your application will crash when you call FREE(), even when the pointer you are passing to FREE() shows a address in the watch window. In this case the pointer has been free'd earlier, check your code for instances of freeing that particular pointer. The easiest possible solution for this problem is replace all your FREE() to FREEIF() calls.

3. Double Release problem.

In this case, your application will crash when you release a interface, the reason is same as the double free problem above. You are trying to release a interface that is already released. To fix this problem replace all your IXXX_Release() calls to RELEASEIF() macro.

Add the below definition to your source file.

#define RELEASEIF(p) if( (p) != NULL){ \

IBASE_Release((IBase*)p);\

(p) = NULL; \

}

Unlike a JAVA Application which will throw an exception, the invalid memory access could crash the entire phone causing it to restart.

2 Responses to "Common reasons for Application Crash in BREW"

Prady responded on April 18, 2008 at 2:24 AM #

You could add the effect of not freeing a pointer to this list too.

Well, this can cause a crash if the pointer allocates big image files...

Karthik responded on April 18, 2008 at 4:12 AM #

I thought of adding that to common simulator errors, wherein you`ll get a popup saying the "memory is not free'd" when you exit the application.