]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
media formats: fix ref leak of peer for mwi subscription
authorScott Griepentrog <sgriepentrog@digium.com>
Tue, 15 Jul 2014 17:14:57 +0000 (17:14 +0000)
committerScott Griepentrog <sgriepentrog@digium.com>
Tue, 15 Jul 2014 17:14:57 +0000 (17:14 +0000)
Holding a reference to the peer during mwi subscriptions
resulted in a circular reference because the final event
message would not be sent until destruction of the peer.

Instead, pass the name of the peer to the event callback
so that it can fail gracefully after the peer has gone.

ASTERISK-23959
Review: https://reviewboard.asterisk.org/r/3754/

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

channels/chan_sip.c

index 38d2375cd84e902637c71eaba80a7cae09e32d32..089adbad9bd2e7f786713f43f1e68a9a7579538f 100644 (file)
@@ -16971,14 +16971,18 @@ static void sip_peer_hold(struct sip_pvt *p, int hold)
 /*! \brief Receive MWI events that we have subscribed to */
 static void mwi_event_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 {
-       struct sip_peer *peer = userdata;
+       char *peer_name = userdata;
+       struct sip_peer *peer = sip_find_peer(peer_name, NULL, TRUE, FINDALLDEVICES, FALSE, 0);
+
        if (stasis_subscription_final_message(sub, msg)) {
-               ao2_cleanup(peer);
+               ast_assert(peer == NULL);
+               ast_free(peer_name);
                return;
        }
-       if (ast_mwi_state_type() == stasis_message_type(msg)) {
+       if (peer && ast_mwi_state_type() == stasis_message_type(msg)) {
                sip_send_mwi_to_peer(peer, 0);
        }
+       ao2_cleanup(peer);
 }
 
 static void network_change_stasis_subscribe(void)
@@ -27591,8 +27595,11 @@ static void add_peer_mwi_subs(struct sip_peer *peer)
 
                mailbox_specific_topic = ast_mwi_topic(mailbox->id);
                if (mailbox_specific_topic) {
-                       ao2_ref(peer, +1);
-                       mailbox->event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, peer);
+                       char *peer_name = ast_strdup(peer->name);
+                       if (!peer_name) {
+                               return;
+                       }
+                       mailbox->event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, peer_name);
                }
        }
 }