]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_session: Fix stream name memory leak.
authorJoshua C. Colp <jcolp@sangoma.com>
Tue, 22 Sep 2020 10:05:34 +0000 (07:05 -0300)
committerJoshua Colp <jcolp@sangoma.com>
Wed, 23 Sep 2020 15:58:33 +0000 (10:58 -0500)
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

res/res_pjsip_session.c

index cd31acaddc89f466760cea1c016689b02542f176..42edaf6ab95c9d9c7780988962542b33a368d0fa 100644 (file)
@@ -803,7 +803,7 @@ static int handle_incoming_sdp(struct ast_sip_session *session, const pjmedia_sd
                }
                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 &&
@@ -819,17 +819,19 @@ static int handle_incoming_sdp(struct ast_sip_session *session, const pjmedia_sd
                        }
 
                        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",