[Asterisk-code-review] stasis/endpoint: Fix memory leak of channel ids in ast endpo... (asterisk[master])

Mohit Dhiman asteriskteam at digium.com
Sat Jan 12 02:35:36 CST 2019


Mohit Dhiman has uploaded this change for review. ( https://gerrit.asterisk.org/10872


Change subject: stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure.
......................................................................

stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure.

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: I97ce73da390af20fd082fb09d722a6fe9cb2f39d
---
M include/asterisk/channel.h
M main/channel.c
M main/channel_internal_api.c
3 files changed, 26 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/72/10872/1

diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 58a4879..e2f7959 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -2659,6 +2659,18 @@
 void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);
 
 /*!
+ * \brief Swap endpoint_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(struct ast_channel *a, struct ast_channel *b);
+
+/*!
  * \brief Swap snapshots beteween two channels
  * \param a First channel
  * \param b Second channel
diff --git a/main/channel.c b/main/channel.c
index 7e12f30..a431e24 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -6790,6 +6790,11 @@
 	/* Make sure the Stasis topic on the channel is updated appropriately */
 	ast_channel_internal_swap_topics(clonechan, original);
 
+	/* Swap endpoint forward so channel created with endpoint exchanges its state 
+	 * with other channel for proper endpoint cleanup.
+	 */
+	ast_channel_internal_swap_endpoint_forward(clonechan, original);
+
 	/* The old snapshots need to follow the channels so the snapshot update is correct */
 	ast_channel_internal_swap_snapshots(clonechan, original);
 
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index 30d3909..22a2bb6 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -1438,6 +1438,15 @@
 	b->channel_forward = forward;
 }
 
+void ast_channel_internal_swap_endpoint_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;
+}
+
 void ast_channel_internal_swap_snapshots(struct ast_channel *a, struct ast_channel *b)
 {
 	struct ast_channel_snapshot *snapshot;

-- 
To view, visit https://gerrit.asterisk.org/10872
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I97ce73da390af20fd082fb09d722a6fe9cb2f39d
Gerrit-Change-Number: 10872
Gerrit-PatchSet: 1
Gerrit-Owner: Mohit Dhiman <mohitdhiman at drishti-soft.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190112/635a2875/attachment.html>


More information about the asterisk-code-review mailing list