<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10862">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua C. Colp: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><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, 30 insertions(+), 0 deletions(-)<br><br></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 3f22cdd..7a5a4ef 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2650,6 +2650,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 6c6e9f7..8f27822 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -6819,6 +6819,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 a963a7d..5269715 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -1388,6 +1388,18 @@</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%);">+    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%);">+</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%);">+}</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/10862">change 10862</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/10862"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ied0451f378a3f2a36acc8c0984959a69895efa17 </div>
<div style="display:none"> Gerrit-Change-Number: 10862 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Mohit Dhiman <mohitdhiman@drishti-soft.com> </div>
<div style="display:none"> Gerrit-Reviewer: Chris Savinovich <csavinovich@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>