diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 1f987e7d11..0d5930d619 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -5893,8 +5893,12 @@ void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist) } if (p->udptl) ast_udptl_destroy(p->udptl); - if (p->refer) + if (p->refer) { + if (p->refer->refer_call) { + p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); + } ast_free(p->refer); + } if (p->route) { free_old_route(p->route); p->route = NULL; @@ -23310,6 +23314,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int if (subscription->owner) { ast_channel_unlock(subscription->owner); } + subscription = dialog_unref(subscription, "unref dialog subscription"); } } @@ -23328,7 +23333,6 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int if (p->refer->refer_call == p) { ast_log(LOG_NOTICE, "INVITE with replaces into it's own call id (%s == %s)!\n", replace_id, p->callid); - p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ error = 1; } @@ -23356,6 +23360,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int if (p->refer->refer_call->owner) { ast_channel_unlock(p->refer->refer_call->owner); } + p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); } refer_locked = 0; p->invitestate = INV_COMPLETED;