]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_stasis: Plug reference leak on stolen channels
authorGeorge Joseph <gjoseph@digium.com>
Fri, 16 Jun 2017 14:31:04 +0000 (08:31 -0600)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 16 Jun 2017 20:06:56 +0000 (15:06 -0500)
When a stasis channel is stolen by another app, the control
structure is unreffed but never unlinked from the app_controls
container.  This causes the channel reference to leak.

Added OBJ_UNLINK to the callback in channel_stolen_cb.

Also added some additional channel lifecycle debug messages to
channel.c.

ASTERISK-27059 #close
Repoorted-by: George Joseph
Change-Id: Ib820936cd49453f20156971785e7f4f182c56e14

main/channel.c
res/res_stasis.c

index 2addfb53b98c4174f241fea30da161f8ffb67f03..c5060b7055e885dd583db077ab36f10e762f1d97 100644 (file)
@@ -1001,6 +1001,9 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char
         * the world know of its existance
         */
        ast_channel_stage_snapshot_done(tmp);
+
+       ast_debug(1, "Channel %p '%s' allocated\n", tmp, ast_channel_name(tmp));
+
        return tmp;
 }
 
@@ -2227,6 +2230,8 @@ static void ast_channel_destructor(void *obj)
        char device_name[AST_CHANNEL_NAME];
        struct ast_callid *callid;
 
+       ast_debug(1, "Channel %p '%s' destroying\n", chan, ast_channel_name(chan));
+
        /* Stop monitoring */
        if (ast_channel_monitor(chan)) {
                ast_channel_monitor(chan)->stop(chan, 0);
@@ -2672,6 +2677,9 @@ void ast_hangup(struct ast_channel *chan)
                return;
        }
 
+       ast_debug(1, "Channel %p '%s' hanging up.  Refs: %d\n", chan, ast_channel_name(chan),
+               ao2_ref(chan, 0));
+
        ast_autoservice_stop(chan);
 
        ast_channel_lock(chan);
@@ -2731,7 +2739,6 @@ void ast_hangup(struct ast_channel *chan)
                ast_assert(ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING) == 0);
        }
 
-       ast_debug(1, "Hanging up channel '%s'\n", ast_channel_name(chan));
        if (ast_channel_tech(chan)->hangup) {
                ast_channel_tech(chan)->hangup(chan);
        }
index 9d7bc4c2433550b3b591ed25e08490379cc045ca..b1cea3ad5c8d83d613077f4e7103a377fe4a877a 100644 (file)
@@ -1057,8 +1057,18 @@ static void channel_stolen_cb(void *data, struct ast_channel *old_chan, struct a
 {
        struct stasis_app_control *control;
 
-       /* find control */
-       control = ao2_callback(app_controls, 0, masq_match_cb, old_chan);
+       /*
+        * At this point, old_chan is the channel pointer that is in Stasis() and
+        * has the unknown channel's name in it while new_chan is the channel pointer
+        * that is not in Stasis(), but has the guts of the channel that Stasis() knows
+        * about.
+        *
+        * Find and unlink control since the channel has a new name/uniqueid
+        * and its hash has changed.  Since the channel is leaving stasis don't
+        * bother putting it back into the container.  Nobody is going to
+        * remove it from the container later.
+        */
+       control = ao2_callback(app_controls, OBJ_UNLINK, masq_match_cb, old_chan);
        if (!control) {
                ast_log(LOG_ERROR, "Could not find control for masqueraded channel\n");
                return;
@@ -1099,8 +1109,10 @@ static void channel_replaced_cb(void *data, struct ast_channel *old_chan, struct
                return;
        }
 
-       /* find, unlink, and relink control since the channel has a new name and
-        * its hash has likely changed */
+       /*
+        * Find, unlink, and relink control since the channel has a new
+        * name/uniqueid and its hash has changed.
+        */
        control = ao2_callback(app_controls, OBJ_UNLINK, masq_match_cb, new_chan);
        if (!control) {
                ast_log(LOG_ERROR, "Could not find control for masquerading channel\n");