From: Matthew Nicholson Date: Tue, 29 Sep 2009 20:25:14 +0000 (+0000) Subject: Avoid a deadlock in chanspy, just in case the spyee is masqueraded and chanspy_ds_cha... X-Git-Tag: 1.6.1.7-rc2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=185e4321a73a922ef5062b850cf25409eb0be50f;p=thirdparty%2Fasterisk.git Avoid a deadlock in chanspy, just in case the spyee is masqueraded and chanspy_ds_chan_fixup() is called with the channel locked. (closes issue #15965) Reported by: atis Patches: chanspy-deadlock-fix1.diff uploaded by mnicholson (license 96) Tested by: atis git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@220938 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index 7317e35785..0932a842d1 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -337,9 +337,10 @@ static int channel_spy(struct ast_channel *chan, struct chanspy_ds *spyee_chansp ast_channel_unlock(chan); ast_mutex_lock(&spyee_chanspy_ds->lock); - if (spyee_chanspy_ds->chan) { - spyee = spyee_chanspy_ds->chan; - ast_channel_lock(spyee); + while ((spyee = spyee_chanspy_ds->chan) && ast_channel_trylock(spyee)) { + /* avoid a deadlock here, just in case spyee is masqueraded and + * chanspy_ds_chan_fixup() is called with the channel locked */ + DEADLOCK_AVOIDANCE(&spyee_chanspy_ds->lock); } ast_mutex_unlock(&spyee_chanspy_ds->lock);