Check the return value of gst_bin_add() 32/319032/1
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 10 Oct 2024 01:28:30 +0000 (10:28 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 14 Oct 2024 01:14:15 +0000 (10:14 +0900)
[Version] 0.4.66
[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 e49722912f199561447d86e612eb82d02cf5379b..f7f0f2b9687d9eb8b98efc0e6fffd4885c972c7e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.65
+Version:    0.4.66
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index b3103496b24e5b86db2239b1778e895e600087c4..e9f799a6f54400911ed74c038dea7b02d9ad9f3c 100644 (file)
@@ -733,10 +733,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));
 
@@ -753,8 +758,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 fec84a587cbb9935eaf64ba1dd4612dbf2ef59ed..67bea7e2746281d88ddf0f4638ed711172e3d697 100644 (file)
@@ -588,7 +588,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;
 }