]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure.
authormohitdhiman <mohitdhiman@drishti-soft.com>
Mon, 7 Jan 2019 18:04:43 +0000 (23:34 +0530)
committerMohit Dhiman <mohitdhiman@drishti-soft.com>
Fri, 11 Jan 2019 14:01:57 +0000 (09:01 -0500)
During Bridging of two channels if masquerade operation is performed on a
channel (clone channel) which was created with endpoint details
(ast_channel_alloc_with_endpoint()) and the original channel which is created
without endpoint details (ast_channel_alloc()) then both the channels must
exchange their endpoint details or else after masquerade when clone channel
is being destroyed the endpoint cleanup callbacks will be destroyed too and
after call completion unique_id of original channel will still be there in
ast_endpoint structure's channel_ids container.

ASTERISK-28197

Change-Id: Ied0451f378a3f2a36acc8c0984959a69895efa17

include/asterisk/channel.h
main/channel.c
main/channel_internal_api.c

index 3f22cdd9c5ce74d6a2358061ef61e46381f69bfb..7a5a4efa81735c82ad0698453e9c88e3b79f46dc 100644 (file)
@@ -2649,6 +2649,18 @@ void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, stru
  */
 void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);
 
+/*!
+ * \brief Swap endpoint_forward and endpoint_cache_forward between two channels
+ * \param a First channel
+ * \param b Second channel
+ * \return void
+ *
+ * \note
+ * This is used in masquerade to exchange endpoint details if one of the two or both
+ * the channels were created with endpoint
+ */
+void ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(struct ast_channel *a, struct ast_channel *b);
+
 /*!
  * \brief Set uniqueid and linkedid string value only (not time)
  * \param chan The channel to set the uniqueid to
index 6c6e9f758b4e12a321249b679362e4ad3ca34303..8f27822be288810fe00ee1a4b8fd5fad4ddb5ca2 100644 (file)
@@ -6819,6 +6819,12 @@ static void channel_do_masquerade(struct ast_channel *original, struct ast_chann
        /* Make sure the Stasis topic on the channel is updated appropriately */
        ast_channel_internal_swap_topics(clonechan, original);
 
+       /* Swap endpoint forward and endpoint cache forward details of the channels,
+        * so channel created with endpoint exchanges its state with other channel
+        * for proper endpoint cleanup.
+        */
+       ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(clonechan, original);
+
        /* Swap channel names. This uses ast_channel_name_set directly, so we
         * don't get any spurious rename events.
         */
index a963a7d3ea03e13a30b7e1d2e454fdee42390468..5269715fde588cd831c36884a69a2fdd7842024f 100644 (file)
@@ -1388,6 +1388,18 @@ void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel
        b->topics = temp;
 }
 
+void ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(struct ast_channel *a, struct ast_channel *b)
+{
+       struct stasis_forward *temp;
+       temp = a->endpoint_forward;
+       a->endpoint_forward = b->endpoint_forward;
+       b->endpoint_forward = temp;
+
+       temp = a->endpoint_cache_forward;
+       a->endpoint_cache_forward = b->endpoint_cache_forward;
+       b->endpoint_cache_forward = temp;
+}
+
 void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid)
 {
        ast_copy_string(chan->uniqueid.unique_id, uniqueid, sizeof(chan->uniqueid.unique_id));