res_pjsip_t38: Better error checking for t38_create_media_state.
authorCorey Farrell <git@cfware.com>
Tue, 7 Nov 2017 17:34:19 +0000 (12:34 -0500)
committerCorey Farrell <git@cfware.com>
Tue, 7 Nov 2017 17:34:19 +0000 (12:34 -0500)
Change-Id: I81b2587427c6982aa3e2a3f9ad69cce8d316eb10

res/res_pjsip_t38.c

index 48cbab3..8f1905f 100644 (file)
@@ -363,7 +363,11 @@ static struct ast_sip_session_media_state *t38_create_media_state(struct ast_sip
        }
 
        ast_stream_set_state(stream, AST_STREAM_STATE_SENDRECV);
-       ast_stream_topology_set_stream(media_state->topology, 0, stream);
+       if (ast_stream_topology_set_stream(media_state->topology, 0, stream)) {
+               ast_stream_free(stream);
+               ast_sip_session_media_state_free(media_state);
+               return NULL;
+       }
 
        caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
        if (!caps) {
@@ -371,9 +375,14 @@ static struct ast_sip_session_media_state *t38_create_media_state(struct ast_sip
                return NULL;
        }
 
-       ast_format_cap_append(caps, ast_format_t38, 0);
        ast_stream_set_formats(stream, caps);
+       /* stream holds a reference to cap, release the local reference
+        * now so we don't have to deal with it in the error condition. */
        ao2_ref(caps, -1);
+       if (ast_format_cap_append(caps, ast_format_t38, 0)) {
+               ast_sip_session_media_state_free(media_state);
+               return NULL;
+       }
 
        session_media = ast_sip_session_media_state_add(session, media_state, AST_MEDIA_TYPE_IMAGE, 0);
        if (!session_media) {