From: Richard Mudgett Date: Thu, 29 Nov 2012 22:58:28 +0000 (+0000) Subject: chan_local: Fix local_pvt ref leak in local_devicestate(). X-Git-Tag: 10.12.0-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=827a3924acd1ec8cf958e0c22e3dad1acf4bef19;p=thirdparty%2Fasterisk.git chan_local: Fix local_pvt ref leak in local_devicestate(). Regression introduced by ASTERISK-20390 fix. (closes issue ASTERISK-20769) Reported by: rmudgett Tested by: rmudgett ........ Merged revisions 376868 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@376869 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_local.c b/channels/chan_local.c index f81aa95664..768fafc6a0 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -307,15 +307,20 @@ static int local_devicestate(void *data) res = AST_DEVICE_NOT_INUSE; it = ao2_iterator_init(locals, 0); - while ((lp = ao2_iterator_next(&it)) && (res == AST_DEVICE_NOT_INUSE)) { - if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) { - ao2_lock(lp); - if (ast_test_flag(lp, LOCAL_LAUNCHED_PBX)) { - res = AST_DEVICE_INUSE; - } - ao2_unlock(lp); + for (; (lp = ao2_iterator_next(&it)); ao2_ref(lp, -1)) { + int is_inuse; + + ao2_lock(lp); + is_inuse = !strcmp(exten, lp->exten) + && !strcmp(context, lp->context) + && lp->owner + && ast_test_flag(lp, LOCAL_LAUNCHED_PBX); + ao2_unlock(lp); + if (is_inuse) { + res = AST_DEVICE_INUSE; + ao2_ref(lp, -1); + break; } - ao2_ref(lp, -1); } ao2_iterator_destroy(&it);