Commit 898faee5 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix potential crash when a channel gets disconnected remotely

It corresponds to the following backtrace observed on android:

  [exec] Stack frame #00  pc 0034aa74  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so: Routine belle_sip_channel_process_read_data at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/channel.c>:607
     [exec] Stack frame #1  pc 0034aad8  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (belle_sip_channel_process_data+48): Routine belle_sip_channel_process_data at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/channel.c>:615
     [exec] Stack frame #2  pc 003805ec  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so: Routine on_udp_data at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/transports/udp_listeningpoint.c>:190
     [exec] Stack frame #3  pc 00225300  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (belle_sip_main_loop_iterate+904): Routine belle_sip_main_loop_iterate at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/belle_sip_loop.c>:448
     [exec] Stack frame #4  pc 0022545c  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (belle_sip_main_loop_run+36): Routine belle_sip_main_loop_run at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/belle_sip_loop.c>:478
     [exec] Stack frame #05  pc 00225508  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (belle_sip_main_loop_sleep+76): Routine belle_sip_main_loop_sleep at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/belle_sip_loop.c>:490
     [exec] Stack frame #06  pc 00376288  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (belle_sip_stack_sleep+40): Routine belle_sip_stack_sleep at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/belle-sip/build/android/../../src/sipstack.c>:204
     [exec] Stack frame #07  pc 000e525c  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (sal_iterate+32): Routine sal_iterate at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../coreapi/bellesip_sal/sal_impl.c>:775
     [exec] Stack frame #08  pc 00127258  /data/app-lib/org.linphone.tester-2/liblinphone-armeabi-v7a.so (linphone_core_iterate+1224): Routine linphone_core_iterate at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../coreapi/linphonecore.c>:2663
     [exec] Stack frame #09  pc 00095408  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so (wait_for_list+68): Routine wait_for_list at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/tester.c>:207 (discriminator 2)
     [exec] Stack frame #10  pc 0008cd2c  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so: Routine io_recv_error_late_recovery at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/register_tester.c>:755
     [exec] Stack frame #11  pc 00007d54  /data/app-lib/org.linphone.tester-2/libcunit.so: Routine run_single_test at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/externals/build/cunit/../../cunit/CUnit/Sources/Framework/TestRun.c>:1002
     [exec] Stack frame #12  pc 0000518c  /data/app-lib/org.linphone.tester-2/libcunit.so (CU_run_test+660): Routine CU_run_test at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/externals/build/cunit/../../cunit/CUnit/Sources/Framework/TestRun.c>:484
     [exec] Stack frame #13  pc 0001123c  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so (bc_tester_run_tests+476): Routine bc_tester_run_tests at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/common/bc_tester_utils.c>:298
     [exec] Stack frame #14  pc 00011ea8  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so (bc_tester_start+176): Routine bc_tester_start at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/common/bc_tester_utils.c>:521
     [exec] Stack frame #15  pc 00053d98  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so (main+1120): Routine main at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/liblinphone_tester.c>:245
     [exec] Stack frame #16  pc 00053650  /data/app-lib/org.linphone.tester-2/liblinphone_tester-armeabi-v7a.so (Java_org_linphone_tester_Tester_run+304): Routine Java_org_linphone_tester_Tester_run at <http://office.linphone.org:8080/job/linphone-android-liblinphone-tester/ws/liblinphone_tester/../jni/..//submodules/linphone/build/android/../../tester/liblinphone_tester.c>:117
     [exec] Stack frame #17  pc 0001f108  /data/dalvik-cache/data@app@org.linphone.tester-2.apk@classes.dex
parent 9e0cd4a7
......@@ -591,6 +591,9 @@ static int belle_sip_channel_process_read_data(belle_sip_channel_t *obj){
}
}
belle_sip_channel_process_stream(obj,FALSE);
if (obj->input_stream.state == WAITING_MESSAGE_START){
channel_end_recv_background_task(obj);
}/*if still in message acquisition state, keep the backgroud task*/
} else if (num == 0) {
/*before closing the channel, check if there was a pending message to receive, whose body acquisition is to be finished.*/
belle_sip_channel_process_stream(obj,TRUE);
......@@ -604,8 +607,6 @@ static int belle_sip_channel_process_read_data(belle_sip_channel_t *obj){
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
ret=BELLE_SIP_STOP;
}
if (obj->input_stream.state == WAITING_MESSAGE_START)
channel_end_recv_background_task(obj);
return ret;
}
......@@ -850,6 +851,10 @@ static void channel_end_recv_background_task(belle_sip_channel_t *obj){
static void channel_invoke_state_listener(belle_sip_channel_t *obj){
if (obj->state==BELLE_SIP_CHANNEL_DISCONNECTED || obj->state==BELLE_SIP_CHANNEL_ERROR){
/*the background tasks must be released "after" notifying the app of the disconnected or error state
By "after" it is means not before the main loop iteration that will notify the app*/
channel_end_send_background_task(obj);
channel_end_recv_background_task(obj);
belle_sip_channel_close(obj);
}
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_state_changed,obj,obj->state);
......@@ -880,7 +885,6 @@ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){
}/*else the channel was previously working good with the current ip address but now fails, so let's notify the error*/
obj->state=BELLE_SIP_CHANNEL_ERROR;
channel_end_send_background_task(obj);
/*Because error notification will in practice trigger the destruction of possible transactions and this channel,
* it is safer to invoke the listener outside the current call stack.
* Indeed the channel encounters network errors while being called for transmiting by a transaction.
......@@ -911,9 +915,6 @@ void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state
belle_sip_channel_handle_error(obj);
}else{
obj->state=state;
if (state==BELLE_SIP_CHANNEL_DISCONNECTED){
channel_end_send_background_task(obj);
}
channel_invoke_state_listener(obj);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment