<p>Mohit Dhiman has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10872">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: I97ce73da390af20fd082fb09d722a6fe9cb2f39d<br>---<br>M include/asterisk/channel.h<br>M main/channel.c<br>M main/channel_internal_api.c<br>3 files changed, 26 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/72/10872/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 58a4879..e2f7959 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2659,6 +2659,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 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(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 Swap snapshots beteween two channels</span><br><span>  * \param a First channel</span><br><span>  * \param b Second channel</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index 7e12f30..a431e24 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -6790,6 +6790,11 @@</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 so channel created with endpoint exchanges its state </span><br><span style="color: hsl(120, 100%, 40%);">+         * with other channel 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(clonechan, original);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>   /* The old snapshots need to follow the channels so the snapshot update is correct */</span><br><span>        ast_channel_internal_swap_snapshots(clonechan, original);</span><br><span> </span><br><span>diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c</span><br><span>index 30d3909..22a2bb6 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -1438,6 +1438,15 @@</span><br><span>      b->channel_forward = forward;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void ast_channel_internal_swap_endpoint_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%);">+   struct stasis_forward *temp;</span><br><span style="color: hsl(120, 100%, 40%);">+</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%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ast_channel_internal_swap_snapshots(struct ast_channel *a, struct ast_channel *b)</span><br><span> {</span><br><span>   struct ast_channel_snapshot *snapshot;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10872">change 10872</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/10872"/><meta itemprop="name" content="View Change"/></div></div>

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