diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 9d0540d420b97f1251dc5b5dd60090d265637f76..a4748d20e4f2a3bcfa8f13386f36223e13728bb3 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -3151,9 +3151,11 @@ static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint, char errmsg[PJ_ERR_MSG_SIZE]; if (timeout > 0) { - pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(endpt), + int timers_cancelled = pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(endpt), req_wrapper->timeout_timer, TIMER_INACTIVE); - ao2_ref(req_wrapper, -1); + if (timers_cancelled > 0) { + ao2_ref(req_wrapper, -1); + } } /* Complain of failure to send the request. */