[Asterisk-code-review] res_pjsip_session: Fix stream name memory leak. (asterisk[16])

Joshua Colp asteriskteam at digium.com
Wed Sep 23 10:50:11 CDT 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14932 )

Change subject: res_pjsip_session: Fix stream name memory leak.
......................................................................

res_pjsip_session: Fix stream name memory leak.

When constructing a stream name based on the media type
and position the allocated name was not being freed
causing a leak.

Change-Id: I52510863b24a2f531f0a55b440bb2c81844029de
---
M res/res_pjsip_session.c
1 file changed, 4 insertions(+), 2 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 0091113..9178174 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -802,7 +802,7 @@
 		}
 		if (!stream) {
 			struct ast_stream *existing_stream = NULL;
-			char *stream_name = NULL;
+			char *stream_name = NULL, *stream_name_allocated = NULL;
 			const char *stream_label = NULL;
 
 			if (session->active_media_state->topology &&
@@ -818,17 +818,19 @@
 			}
 
 			if (ast_strlen_zero(stream_name)) {
-				if (ast_asprintf(&stream_name, "%s-%d", ast_codec_media_type2str(type), i) < 0) {
+				if (ast_asprintf(&stream_name_allocated, "%s-%d", ast_codec_media_type2str(type), i) < 0) {
 					handled = 0;
 					SCOPE_EXIT_LOG_EXPR(goto end, LOG_ERROR, "%s: Couldn't alloc stream name\n",
 						 ast_sip_session_get_name(session));
 
 				}
+				stream_name = stream_name_allocated;
 				ast_trace(-1, "%s: Using %s for new stream name\n", ast_sip_session_get_name(session),
 					stream_name);
 			}
 
 			stream = ast_stream_alloc(stream_name, type);
+			ast_free(stream_name_allocated);
 			if (!stream) {
 				handled = 0;
 				SCOPE_EXIT_LOG_EXPR(goto end, LOG_ERROR, "%s: Couldn't alloc stream\n",

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I52510863b24a2f531f0a55b440bb2c81844029de
Gerrit-Change-Number: 14932
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200923/a20d0dba/attachment.html>


More information about the asterisk-code-review mailing list