From: Sangchul Lee Date: Fri, 14 Jan 2022 05:49:27 +0000 (+0900) Subject: Add omitted error checking in webrtc_create() X-Git-Tag: submit/tizen_6.5/20220118.104924^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F26%2F269426%2F1;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add omitted error checking in webrtc_create() [Version] 0.2.156 [Issue Type] Improvement Change-Id: Ib208fc70c4f477495b8f44a155a85e9ba3c5c123 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 6da55eb4..281aaef3 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 46b83dd9..ff679785 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc.c b/src/webrtc.c index bc424aee..9406af9b 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -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) diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index ee5aeaaa..07a8beb8 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -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; + } } diff --git a/src/webrtc_resource.c b/src/webrtc_resource.c index 7e92cae8..596e4a32 100644 --- a/src/webrtc_resource.c +++ b/src/webrtc_resource.c @@ -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; }