Check the return value of gst_bin_add() 44/318844/3
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 10 Oct 2024 01:28:30 +0000 (10:28 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 10 Oct 2024 03:19:09 +0000 (12:19 +0900)
[Version] 1.1.33
[Issue Type] Coverity defects

Change-Id: I53b005b655caad3543b693e7efef5b83baa90962
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_sink.c
src/webrtc_source_mediapacket.c

index d3b90614ae849017081c4106ac746f3554507377..88c142c880ffe3fb9c409d501306509fe8724a53 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    1.1.32
+Version:    1.1.33
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 74bdaaaf0878240ee26b72b9636f6d60385c76c4..c7e23f7970afe374fd7aab9efe30189fa9f165da 100644 (file)
@@ -732,10 +732,15 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio, we
        g_signal_connect(decodebin, "autoplug-select", G_CALLBACK(_decodebin_autoplug_select_cb), webrtc);
        g_signal_connect(decodebin, "element-added", G_CALLBACK(__decodebin_element_added_cb), sink);
 
-       gst_bin_add(sink->bin, decodebin);
+       if (!gst_bin_add(sink->bin, decodebin)) {
+               LOG_ERROR("failed to gst_bin_add(), adding [%s] to [%s]", GST_ELEMENT_NAME(decodebin), GST_ELEMENT_NAME(sink->bin));
+               goto error_before_insert;
+       }
 
-       if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE)
+       if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE) {
+               gst_bin_remove(sink->bin, decodebin);
                goto error_before_insert;
+       }
 
        ASSERT(g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink));
 
@@ -752,8 +757,7 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio, we
        return WEBRTC_ERROR_NONE;
 
 error_before_insert:
-       if (decodebin)
-               gst_object_unref(GST_OBJECT(decodebin));
+       SAFE_GST_OBJECT_UNREF(decodebin);
        g_free(track_name);
        g_free(sink);
 
index a9dd577697104d74bc49b1b4509af0690e6dc43a..0a0acae46d7d661a121e0beee11b10035e42d7ec 100644 (file)
@@ -591,7 +591,11 @@ int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        _connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "need-data", G_CALLBACK(__appsrc_need_data_cb), source);
        _connect_and_append_signal(&source->signals, G_OBJECT(appsrc), "enough-data", G_CALLBACK(__appsrc_enough_data_cb), source);
 
-       gst_bin_add(source->bin, appsrc);
+       if (!gst_bin_add(source->bin, appsrc)) {
+               LOG_ERROR("failed to gst_bin_add(), adding [%s] to [%s]", GST_ELEMENT_NAME(appsrc), GST_ELEMENT_NAME(source->bin));
+               gst_object_unref(GST_OBJECT(appsrc));
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
 
        return WEBRTC_ERROR_NONE;
 }