App Crashes (Sometimes) With Fatal Signal 11 (Sigsegv), Code 1

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

I found the problem. I don't think this will help a lot of others trying to track down their personal SIGSEGV, but mine (and it was very hard) was entirely related to this:

https://code.google.com/p/android/issues/detail?id=8709

The libcrypto.so in my dump kind of clued me in. I do a MD5 hash of packet data when trying to determine if I've already seen the packet, and skipping it if I had. I thought at one point this was an ugly threading issue related to tracking those hashes, but it turned out it was the java.security.MessageDigest class! It's not thread safe!

I swapped it out with a UID I was stuffing in every packet based on the device UUID and a timestamp. No problems since.

I guess the lesson I can impart to those that were in my situation is, even if you're a 100% Java application, pay attention to the native library and symbol noted in the crash dump for clues. Googling for SIGSEGV + the lib .so name will go a lot farther than the useless code=1, etc... Next think about where your Java app could touch native code, even if it's nothing you're doing. I made the mistake of assuming it was a Service + UI threading issue where the Canvas was drawing something that was null, (the most common case I Googled on SIGSEGV) and ignored the possibility it could have been completely related to code I wrote that was related to the lib .so in the crash dump. Naturally java.security would use a native component in libcrypto.so for speed, so once I clued in, I Googled for Android + SIGSEGV + libcrypto.so and found the documented issue.

How to solve Android Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid xxxxx (Thread-X)?

After some discussion it became clear that the problem was with interaction with memory:

extern "C" 
jdouble
JNICALL Java_com_foo(JNIEnv *env, jclass type, jlong addrRgba, jlong addrGray) {
Mat &mRgb = *(Mat *) addrRgba;
Mat &mGray = *(Mat *) addrGray;

return (jdouble) toGray(mRgb, mGray);
}

As a quick fix double toGray(Mat& rgb, Mat& gray); had to be changed to double toGray(Mat rgb, Mat gray)

Additional information can be found on topic CvMat deep copy

Android error: Fatal signal 11 (SIGSEGV) leads to app crash

I recommend to use a debugger and query more information about the crash (e.g. LLDB). Sometimes you do not even need to set up breakpoints, since the debugger can stop when it catches an error and show you the problematic code (It can be on the native side).

According to this question, bad memory access can lead to SIGSEGV.

Watch out for memory leaks in your app, make sure you are not holding any references to killed Context objects and etc.



Related Topics



Leave a reply



Submit