Commit b34d1a3c authored by Olivier Dion's avatar Olivier Dion Committed by Sébastien Blin

sip: Fix increment of invite session

Increment of the invite session has to be done before SIPCall takes a reference
to it.

Otherwise, `pjsip_inv_dec_ref()` will be called internally by PJSIP when the
reference counter has reached 0.  This happen when `SIPCall::setInviteSession()`
is called in `invite_session_state_changed_cb()`, resulting in the deletion of
the invitation.

Change-Id: Icba0985ea26ce5dec462bd124cca4dd2187d6a47
parent 7e15841b
......@@ -660,6 +660,17 @@ SIPCall::setInviteSession(pjsip_inv_session* inviteSession)
if (inviteSession == nullptr and inviteSession_) {
JAMI_DBG("[call:%s] Delete current invite session", getCallId().c_str());
} else if (inviteSession != nullptr) {
// NOTE: The first reference of the invite session is owned by pjsip. If
// that counter goes down to zero the invite will be destroyed, and the
// unique_ptr will point freed datas. To avoid this, we increment the
// ref counter and let our unique_ptr share the ownership of the session
// with pjsip.
if (PJ_SUCCESS != pjsip_inv_add_ref(inviteSession)) {
JAMI_WARN("[call:%s] trying to set invalid invite session [%p]",
getCallId().c_str(), inviteSession);
inviteSession_.reset(nullptr);
return;
}
JAMI_DBG("[call:%s] Set new invite session [%p]", getCallId().c_str(), inviteSession);
} else {
// Nothing to do.
......
......@@ -509,11 +509,6 @@ transaction_request_cb(pjsip_rx_data* rdata)
pjsip_dlg_dec_lock(dialog);
inv->mod_data[mod_ua_.id] = call.get();
// NOTE: The invitation counter is managed by pjsip. If that counter goes down to zero
// the invite will be destroyed, and the unique_ptr will point freed datas.
// To avoid this, we increment the ref counter and let our unique_ptr manage
// when the invite will be freed
pjsip_inv_add_ref(inv);
call->setInviteSession(inv);
// Check whether Replaces header is present in the request and process accordingly.
......
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