[Asterisk-code-review] streams: Fix one memory leak and one formats ref issue (asterisk[17])

Friendly Automation asteriskteam at digium.com
Wed May 6 07:27:51 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14387 )

Change subject: streams: Fix one memory leak and one formats ref issue
......................................................................

streams: Fix one memory leak and one formats ref issue

ast_stream_topology_create_from_format_cap() was setting the
stream->formats directly but not freeing the default formats.  This
causes a memory leak.

* ast_stream_topology_create_from_format_cap() now calls
  ast_stream_set_formats() which properly cleans up the existing
  stream formats.

When cloning a stream, the source stream's format caps _pointer_ is
copied to the new stream and it's reference count bumped.  If
either stream is set to "removed", this will cause _both_ streams
to have their format caps cleared.

* ast_stream_clone() now creates a new format caps object and copies
  the formats from the source stream instead of just copying the
  pointer.

ASTERISK-28870

Change-Id: If697d81c3658eb7baeea6dab413b13423938fb53
---
M main/stream.c
1 file changed, 9 insertions(+), 4 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, approved
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/main/stream.c b/main/stream.c
index 02e6a54..21dcede 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -137,9 +137,13 @@
 	memcpy(new_stream, stream, sizeof(*new_stream));
 	strcpy(new_stream->name, stream_name); /* Safe */
 	new_stream->group = -1;
-	if (new_stream->formats) {
-		ao2_ref(new_stream->formats, +1);
+
+	new_stream->formats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!new_stream->formats) {
+		ast_free(new_stream);
+		return NULL;
 	}
+	ast_format_cap_append_from_cap(new_stream->formats, stream->formats, AST_MEDIA_TYPE_UNKNOWN);
 
 	new_stream->metadata = ast_stream_get_metadata_list(stream);
 
@@ -585,8 +589,9 @@
 			ast_stream_topology_free(topology);
 			return NULL;
 		}
-		/* We're transferring the initial ref so no bump needed */
-		stream->formats = new_cap;
+
+		ast_stream_set_formats(stream, new_cap);
+		ao2_ref(new_cap, -1);
 		stream->state = AST_STREAM_STATE_SENDRECV;
 		if (ast_stream_topology_append_stream(topology, stream) == -1) {
 			ast_stream_free(stream);

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

Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: If697d81c3658eb7baeea6dab413b13423938fb53
Gerrit-Change-Number: 14387
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200506/fbd1ad51/attachment.html>


More information about the asterisk-code-review mailing list