From: Jeongmo Yang Date: Wed, 19 Jun 2024 05:02:00 +0000 (+0900) Subject: Add defensive code for clearing locked mutex X-Git-Tag: accepted/tizen/unified/20240701.191826~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b35138e5861ab9c47ff1f921939cda43f0e15802;p=platform%2Fcore%2Fapi%2Fcamera.git Add defensive code for clearing locked mutex - The mutex can be cleared although it's locked while calling client user callback. - Add defensive code to avoid clearing locked mutex. [Version] 1.0.2 [Issue Type] Improvement Change-Id: Ib6abaeba5a05c5cdb7f5667c4719c6a2e89bdfe2 Signed-off-by: Jeongmo Yang --- diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 29928a6..75d5fa3 100644 --- a/packaging/capi-media-camera.spec +++ b/packaging/capi-media-camera.spec @@ -1,6 +1,6 @@ Name: capi-media-camera Summary: A Camera API -Version: 1.0.1 +Version: 1.0.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index 1f4fa41..24f0193 100644 --- a/src/camera.c +++ b/src/camera.c @@ -1713,6 +1713,8 @@ static void __camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_ CAM_LOG_WARNING("unhandled event %d", event); break; } + + CAM_LOG_DEBUG("done - event[%d]", event); } static gboolean __camera_idle_event_callback(gpointer data) @@ -2367,8 +2369,17 @@ static void __camera_mutex_cond_clear(camera_cb_info_s *cb_info) g_mutex_clear(&cb_info->mp_data_lock); g_mutex_clear(&cb_info->bridge_lock); - for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) + for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) { + /* The mutex can be locked when the user callback is called in idle callback. + This code will wait until it's unlocked and avoid crash by clearing locked mutex. */ + if (!g_mutex_trylock(&cb_info->user_cb_lock[i])) { + CAM_LOG_WARNING("user_cb_lock[%d] is locked somewhere", i); + g_mutex_lock(&cb_info->user_cb_lock[i]); + } + + g_mutex_unlock(&cb_info->user_cb_lock[i]); g_mutex_clear(&cb_info->user_cb_lock[i]); + } for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) { g_mutex_clear(&cb_info->api_lock[i]);