<p>Mohit Dhiman has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10859">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure.<br><br>During Bridging of two channels if masquerade operation is performed on a<br>channel (clone channel) which was created with endpoint details<br>(ast_channel_alloc_with_endpoint()) and the original channel which is created<br>without endpoint details (ast_channel_alloc()) then both the channels must<br>exchange their endpoint details or else after masquerade when clone channel<br>is being destroyed the endpoint cleanup callbacks will be destroyed too and<br>after call completion unique_id of original channel will still be there in<br>ast_endpoint structure's channel_ids container.<br><br>ASTERISK-28197<br><br>Change-Id: Ied0451f378a3f2a36acc8c0984959a69895efa17<br>---<br>M include/asterisk/channel.h<br>M main/channel.c<br>M main/channel_internal_api.c<br>3 files changed, 47 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/59/10859/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index d709159..0ab12e7 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2589,6 +2589,18 @@</span><br><span> void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Swap endpoint_forward and endpoint_cache_forward between two channels</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param a First channel</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param b Second channel</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return void</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note</span><br><span style="color: hsl(120, 100%, 40%);">+ * This is used in masquerade to exchange endpoint details if one of the two or both</span><br><span style="color: hsl(120, 100%, 40%);">+ * the channels were created with endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(struct ast_channel *a, struct ast_channel *b);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span>  * \brief Set uniqueid and linkedid string value only (not time)</span><br><span>  * \param chan The channel to set the uniqueid to</span><br><span>  * \param uniqueid The uniqueid to set</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index c1eecdb..74d7986 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -6922,6 +6922,12 @@</span><br><span>       /* Make sure the Stasis topic on the channel is updated appropriately */</span><br><span>     ast_channel_internal_swap_topics(clonechan, original);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    /* Swap endpoint forward and endpoint cache forward details of the channels,</span><br><span style="color: hsl(120, 100%, 40%);">+   * so channel created with endpoint exchanges its state with other channel</span><br><span style="color: hsl(120, 100%, 40%);">+     * for proper endpoint cleanup.</span><br><span style="color: hsl(120, 100%, 40%);">+        */</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(clonechan, original);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>        /* Swap channel names. This uses ast_channel_name_set directly, so we</span><br><span>         * don't get any spurious rename events.</span><br><span>          */</span><br><span>diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c</span><br><span>index 72ca1a9..d297cea 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -1546,6 +1546,35 @@</span><br><span>        b->topics = temp;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(struct ast_channel *a, struct ast_channel *b)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    if (a->endpoint_forward && b->endpoint_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+               struct stasis_forward *temp;</span><br><span style="color: hsl(120, 100%, 40%);">+          temp = a->endpoint_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+                a->endpoint_forward = b->endpoint_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+              b->endpoint_forward = temp;</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (a->endpoint_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+          b->endpoint_forward = a->endpoint_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+              a->endpoint_forward = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (b->endpoint_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+          a->endpoint_forward = b->endpoint_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+              b->endpoint_forward = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (a->endpoint_cache_forward && b->endpoint_cache_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+           struct stasis_forward *temp;</span><br><span style="color: hsl(120, 100%, 40%);">+          temp = a->endpoint_cache_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+          a->endpoint_cache_forward = b->endpoint_cache_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+          b->endpoint_cache_forward = temp;</span><br><span style="color: hsl(120, 100%, 40%);">+  } else if (a->endpoint_cache_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+            b->endpoint_cache_forward = a->endpoint_cache_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+          a->endpoint_cache_forward = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  } else if (b->endpoint_cache_forward) {</span><br><span style="color: hsl(120, 100%, 40%);">+            a->endpoint_cache_forward = b->endpoint_cache_forward;</span><br><span style="color: hsl(120, 100%, 40%);">+          b->endpoint_cache_forward = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid)</span><br><span> {</span><br><span>  ast_copy_string(chan->uniqueid.unique_id, uniqueid, sizeof(chan->uniqueid.unique_id));</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10859">change 10859</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10859"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ied0451f378a3f2a36acc8c0984959a69895efa17 </div>
<div style="display:none"> Gerrit-Change-Number: 10859 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Mohit Dhiman <mohitdhiman@drishti-soft.com> </div>