diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index b75be9156..bd942c9aa 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -109,6 +109,7 @@ struct SalOp{ bool_t manual_refresher; bool_t has_auth_pending; bool_t supports_session_timers; + bool_t op_released; }; diff --git a/coreapi/bellesip_sal/sal_op_impl.c b/coreapi/bellesip_sal/sal_op_impl.c index dff9f0713..5a55d2900 100644 --- a/coreapi/bellesip_sal/sal_op_impl.c +++ b/coreapi/bellesip_sal/sal_op_impl.c @@ -38,6 +38,7 @@ void sal_op_release(SalOp *op){ if (op->refresher) { belle_sip_refresher_stop(op->refresher); } + op->op_released = TRUE; sal_op_unref(op); } diff --git a/coreapi/bellesip_sal/sal_op_presence.c b/coreapi/bellesip_sal/sal_op_presence.c index c0fcc25b0..f5ec79ad8 100644 --- a/coreapi/bellesip_sal/sal_op_presence.c +++ b/coreapi/bellesip_sal/sal_op_presence.c @@ -55,7 +55,9 @@ static void presence_process_dialog_terminated(void *ctx, const belle_sip_dialog if (op->dialog) { if (belle_sip_dialog_is_server(op->dialog)){ ms_message("Incoming subscribtion from [%s] terminated",sal_op_get_from(op)); - op->base.root->callbacks.subscribe_presence_closed(op, sal_op_get_from(op)); + if (!op->op_released){ + op->base.root->callbacks.subscribe_presence_closed(op, sal_op_get_from(op)); + } } set_or_update_dialog(op, NULL); } @@ -98,7 +100,9 @@ static void presence_response_event(void *op_base, const belle_sip_response_even if (code>=300) { if (strcmp("SUBSCRIBE",belle_sip_request_get_method(request))==0){ ms_message("subscription to [%s] rejected",sal_op_get_to(op)); - op->base.root->callbacks.notify_presence(op,SalSubscribeTerminated, NULL,NULL); /*NULL = offline*/ + if (!op->op_released){ + op->base.root->callbacks.notify_presence(op,SalSubscribeTerminated, NULL,NULL); /*NULL = offline*/ + } return; } } @@ -156,7 +160,9 @@ static void presence_process_timeout(void *user_ctx, const belle_sip_timeout_eve if (strcmp("SUBSCRIBE",belle_sip_request_get_method(request))==0){ ms_message("subscription to [%s] timeout",sal_op_get_to(op)); - op->base.root->callbacks.notify_presence(op,SalSubscribeTerminated, NULL,NULL); /*NULL = offline*/ + if (!op->op_released){ + op->base.root->callbacks.notify_presence(op,SalSubscribeTerminated, NULL,NULL); /*NULL = offline*/ + } } } @@ -176,12 +182,13 @@ static SalPresenceModel * process_presence_notification(SalOp *op, belle_sip_req return NULL; if (body==NULL) return NULL; - - op->base.root->callbacks.parse_presence_requested(op, + if (!op->op_released){ + op->base.root->callbacks.parse_presence_requested(op, belle_sip_header_content_type_get_type(content_type), belle_sip_header_content_type_get_subtype(content_type), body, &result); + } return result; } @@ -210,7 +217,9 @@ static void handle_notify(SalOp *op, belle_sip_request_t *req, belle_sip_dialog_ /* Presence notification body parsed successfully. */ resp = sal_op_create_response_from_request(op, req, 200); /*create first because the op may be destroyed by notify_presence */ - op->base.root->callbacks.notify_presence(op, sub_state, presence_model, NULL); + if (!op->op_released){ + op->base.root->callbacks.notify_presence(op, sub_state, presence_model, NULL); + } } else if (body){ /* Formatting error in presence notification body. */ ms_warning("Wrongly formatted presence document."); diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 814452ad0..7a068fd8c 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1058,6 +1058,7 @@ static void vfu_request(SalOp *op){ static void dtmf_received(SalOp *op, char dtmf){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); + if (!call) return; linphone_core_notify_dtmf_received(lc, call, dtmf); } diff --git a/coreapi/presence.c b/coreapi/presence.c index b10f1e35f..f69ddec6e 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -1888,10 +1888,17 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa return ; } if (ss==SalSubscribeTerminated){ - sal_op_release(op); if (lf){ - lf->outsub=NULL; + if (lf->outsub != op){ + sal_op_release(op); + } + if (lf->outsub){ + sal_op_release(lf->outsub); + lf->outsub=NULL; + } lf->subscribe_active=FALSE; + }else{ + sal_op_release(op); } } }