Add omitted error checking in webrtc_create() 26/269426/1 submit/tizen_6.5/20220118.104924
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 14 Jan 2022 05:49:27 +0000 (14:49 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 14 Jan 2022 06:15:18 +0000 (15:15 +0900)
[Version] 0.2.156
[Issue Type] Improvement

Change-Id: Ib208fc70c4f477495b8f44a155a85e9ba3c5c123
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_ini.c
src/webrtc_resource.c

index 6da55eb4e6b26693c8ceb506fe4ea23e6eb2fec6..281aaef396e559ddde51bb884c7d993ef647e4e7 100644 (file)
@@ -568,7 +568,7 @@ typedef struct webrtc_signaling_client_s {
        webrtc_callbacks_s message_cb;
 } webrtc_signaling_client_s;
 
-int _load_ini(webrtc_s *webrtc);
+void _load_ini(webrtc_s *webrtc);
 void _unload_ini(webrtc_s *webrtc);
 ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, int type);
 bool _is_resource_required(webrtc_ini_s *ini);
index 46b83dd96200dbef0683bb11b75e5d4d7d22c790..ff6797855fe81af3b837f2eabc09951b3a6054cf 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.155
+Version:    0.2.156
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index bc424aee65f39e01ca5397359a4793826f03c9ac..9406af9b593d51a6a52a19affd9f053b42b9f955 100644 (file)
@@ -70,9 +70,8 @@ int webrtc_unset_error_cb(webrtc_h webrtc)
 
 int webrtc_create(webrtc_h *webrtc)
 {
-#ifndef TIZEN_TV
        int ret = WEBRTC_ERROR_NONE;
-#endif
+       g_autoptr(GMutexLocker) locker = NULL;
        webrtc_s *_webrtc = NULL;
 
        RET_ERR_IF_NETWORK_FEATURES_ARE_NOT_SUPPORTED();
@@ -82,7 +81,7 @@ int webrtc_create(webrtc_h *webrtc)
        _webrtc = g_new0(webrtc_s, 1);
 
        g_mutex_init(&_webrtc->mutex);
-       g_mutex_lock(&_webrtc->mutex);
+       locker = g_mutex_locker_new(&_webrtc->mutex);
 
        g_mutex_init(&_webrtc->desc_mutex);
        g_cond_init(&_webrtc->desc_cond);
@@ -90,20 +89,19 @@ int webrtc_create(webrtc_h *webrtc)
        _load_ini(_webrtc);
        if (_is_resource_required(&_webrtc->ini)) {
 #ifndef TIZEN_TV
-               ret = _create_resource_manager(_webrtc);
-               if (ret != WEBRTC_ERROR_NONE) {
-                       LOG_ERROR("failed to create resource manager");
-                       _unload_ini(_webrtc);
-                       g_mutex_unlock(&_webrtc->mutex);
-                       g_free(_webrtc);
-                       return ret;
-               }
+               if ((ret = _create_resource_manager(_webrtc)) != WEBRTC_ERROR_NONE)
+                       goto error;
 #else
                LOG_WARNING("no resource manager integration yet");
 #endif
        }
-       _gst_init(_webrtc);
-       _gst_build_pipeline(_webrtc);
+
+       if ((ret = _gst_init(_webrtc)) != WEBRTC_ERROR_NONE)
+               goto error;
+
+       if ((ret = _gst_build_pipeline(_webrtc)) != WEBRTC_ERROR_NONE)
+               goto error;
+
        _init_data_channels(_webrtc);
 
        _webrtc->pend_state = WEBRTC_STATE_IDLE;
@@ -113,9 +111,13 @@ int webrtc_create(webrtc_h *webrtc)
 
        LOG_INFO("webrtc[%p] is created", *webrtc);
 
-       g_mutex_unlock(&_webrtc->mutex);
-
        return WEBRTC_ERROR_NONE;
+
+error:
+       _unload_ini(_webrtc);
+       g_free(_webrtc);
+
+       return ret;
 }
 
 int webrtc_destroy(webrtc_h webrtc)
index ee5aeaaa3930deac4e59f50784988ee23f017076..07a8beb87934570857a397e1b94bd1952f926509 100644 (file)
@@ -425,12 +425,12 @@ static void __apply_media_source_setting(webrtc_ini_s *ini, ini_item_media_sourc
                        is_default ? DEFAULT_FEC_PERCENTAGE : ini->media_source.fec_percentage);
 }
 
-int _load_ini(webrtc_s *webrtc)
+void _load_ini(webrtc_s *webrtc)
 {
        webrtc_ini_s *ini;
        int i = 0;
 
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_IF(webrtc == NULL, "webrtc is NULL");
 
        memset(&webrtc->ini, 0, sizeof(webrtc_ini_s));
        ini = &webrtc->ini;
@@ -492,8 +492,6 @@ int _load_ini(webrtc_s *webrtc)
                __apply_vpxenc_params_setting(ini, &ini->vpxenc_params, INI_CATEGORY_VPXENC_PARAMS);
 
        __dump_ini(ini);
-
-       return WEBRTC_ERROR_NONE;
 }
 
 ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, int type)
@@ -533,7 +531,9 @@ void _unload_ini(webrtc_s *webrtc)
        g_strfreev(webrtc->ini.general.gst_excluded_elements);
        webrtc->ini.general.gst_excluded_elements = NULL;
 
-       iniparser_freedict(webrtc->ini.dict);
-       LOG_DEBUG("ini instance[%p] is freed", webrtc->ini.dict);
-       webrtc->ini.dict = NULL;
+       if (webrtc->ini.dict) {
+               iniparser_freedict(webrtc->ini.dict);
+               LOG_DEBUG("ini instance[%p] is freed", webrtc->ini.dict);
+               webrtc->ini.dict = NULL;
+       }
 }
index 7e92cae84f084dc78901cc51079fc6c8d09b3ab6..596e4a32e9849667ef9cd48409a203628eba3a3f 100644 (file)
@@ -72,7 +72,7 @@ int _create_resource_manager(webrtc_s *webrtc)
        if (mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
                                __resource_release_cb, webrtc,
                                &webrtc->resource.mgr) != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               LOG_ERROR("Failed to init resource manager for media");
+               LOG_ERROR("failed to init resource manager for media");
                return WEBRTC_ERROR_RESOURCE_FAILED;
        }