If non-magic pickup (no "pickup-" in callid) is used, chan_sip locks the
channel it wants to pick up, and a bit further down, it locks the
channel list when allocating a new channel.
That causes a deadlock when another part of the code traverses over the
channel list, locking all the channels one by one.
This changeset fixes it by releasing the locks before calling sip_new
and reacquiring them afterwards. Unfortunately this involves doing the
checks we already did again (because the channel may have changed).
While trying to avoid duplicate code, I did some refactoring for
readability:
- if refer_locked == 1, we guarantee there is a locked channel
- magic_callid holds a cached version of !ast_strlen_zero(pickup.exten)
This is for branch 11 only. It appears that the changed code in 13 does
not lock the components like it does in 11 and below. Reproducing the
deadlock on 13 has thusfar failed.