diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index dd465365bed341b56458b8913e9bbc60c6c858d1..bdff928697b48ba41f3b39750423cc13b811e530 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -9874,6 +9874,7 @@ static int iax2_poke_peer_cb(void *obj, void *arg, int flags) static int iax2_poke_peer(struct iax2_peer *peer, int heldcall) { + int callno; if (!peer->maxms || (!peer->addr.sin_addr.s_addr && !peer->dnsmgr)) { /* IF we have no IP without dnsmgr, or this isn't to be monitored, return immediately after clearing things out */ @@ -9883,11 +9884,13 @@ static int iax2_poke_peer(struct iax2_peer *peer, int heldcall) peer->callno = 0; return 0; } - if (peer->callno > 0) { + + /* The peer could change the callno inside iax2_destroy, since we do deadlock avoidance */ + if ((callno = peer->callno) > 0) { ast_log(LOG_NOTICE, "Still have a callno...\n"); - ast_mutex_lock(&iaxsl[peer->callno]); - iax2_destroy(peer->callno); - ast_mutex_unlock(&iaxsl[peer->callno]); + ast_mutex_lock(&iaxsl[callno]); + iax2_destroy(callno); + ast_mutex_unlock(&iaxsl[callno]); } if (heldcall) ast_mutex_unlock(&iaxsl[heldcall]);