]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fixup glare detection, to fix a memory leak of a local pvt structure.
authorTilghman Lesher <tilghman@meg.abyt.es>
Mon, 16 Mar 2009 15:39:15 +0000 (15:39 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Mon, 16 Mar 2009 15:39:15 +0000 (15:39 +0000)
(closes issue #14656)
 Reported by: caspy
 Patches:
       20090313__bug14656__2.diff.txt uploaded by tilghman (license 14)
 Tested by: caspy

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@182208 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_local.c

index a400a6363ec8fcf1398b5a2af0e6d96ec959a92f..db8bec313b59ff77cef725e06f3b8f550686dc3e 100644 (file)
@@ -168,23 +168,17 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
        /* Recalculate outbound channel */
        other = isoutbound ? p->owner : p->chan;
 
-       /* Set glare detection */
-       ast_set_flag(p, LOCAL_GLARE_DETECT);
-       if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
-               /* We had a glare on the hangup.  Forget all this business,
-               return and destroy p.  */
-               ast_mutex_unlock(&p->lock);
-               p = local_pvt_destroy(p);
-               return -1;
-       }
        if (!other) {
-               ast_clear_flag(p, LOCAL_GLARE_DETECT);
                return 0;
        }
 
        /* do not queue frame if generator is on both local channels */
-       if (us && us->generator && other->generator)
+       if (us && us->generator && other->generator) {
                return 0;
+       }
+
+       /* Set glare detection */
+       ast_set_flag(p, LOCAL_GLARE_DETECT);
 
        /* Ensure that we have both channels locked */
        while (other && ast_channel_trylock(other)) {
@@ -202,6 +196,17 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
                other = isoutbound ? p->owner : p->chan;
        }
 
+       /* Since glare detection only occurs within this function, and because
+        * a pvt flag cannot be set without having the pvt lock, this is the only
+        * location where we could detect a cancelling of the queue. */
+       if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
+               /* We had a glare on the hangup.  Forget all this business,
+               return and destroy p.  */
+               ast_mutex_unlock(&p->lock);
+               p = local_pvt_destroy(p);
+               return -1;
+       }
+
        if (other) {
                ast_queue_frame(other, f);
                ast_channel_unlock(other);