How to investigate and fix libpjsua2.so crash

593 views Asked by At
SIGSEGV SEGV_MAPERR at 0x00000008

0  libpjsua2.so                   0x56585a88 pj::Call::getInfo() const
1  libpjsua2.so                   0x56546b44 std::allocator<pj::CallMediaInfo>::allocator()

I'm using pjsip for one of my hobby project(complies with GPL). Above you can see the stacktrace received from crashlytics. I'm using Java wrapper for pjsip.

There are a lot of users(50 %) affected by this error, however I'm not able to reproduce it on my local devices.

Not sure but I suspect that following java call lead to error. Which call C++ via JNI

public void notifyCallState(MyCall call) {
    if (currentCall == null || call.getId() != currentCall.getId())
        return;

    CallInfo ci;
    try {
        ci = call.getInfo();
    } catch (Exception e) {
        ci = null;
    }
    Message m = Message.obtain(handler, MSG_TYPE.CALL_STATE, ci);
    m.sendToTarget();

    if (ci != null && ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) {
        currentCall = null;
    }
}

Code snippet is taken from examples which come from psjua download. Link to http repo. My code is the same. Any help highly appreciated

2

There are 2 answers

2
domen On

From the stacktrace is looks like call is null, and getId method is at 0x8 offset.

If that's really the case, the fix is to make sure notifyCallState isn't called with null argument, or to check it inside the method, i.e.:

if (call == null || currentCall == null || call.getId() != currentCall.getId())
    return;
0
Mantosh Kumar On

Your program is most likely hitting some sort of memory corruption and most likely heap memory. Following observations points towards that.

  1. I'm not able to reproduce it on my local devices. This is common symptoms of memory corruption.
  2. stack-trace includes std::allocator which indicates that program has been terminated while using(creating/deleting/accessing) the heap memory.

Recommendation

  1. We should try to review the code logic and whether this program uses Interop service in correct way.I do not have much idea regarding this however it looks like your program logic does have JAVA/C++ interaction. If we are lucky we might get something obvious here and we are done.
  2. If the stack-trace are after effect of something else, then we are in trouble we might have to take approach suggested in below posts.

Windows Platform

https://stackoverflow.com/a/22074401/2724703

Linux Platform

https://stackoverflow.com/a/22658693/2724703

Android Platform

https://stackoverflow.com/a/22663360/2724703

You may want to refer the above posts to get the idea about how to approach on such problems. As per my understanding, android platform does not have dynamic tools so you might have to use some versions(debug/additional logging) of your library.

I do hope that, above information might be useful and would have given some guidelines to approach your problem.