From e549a7569adeabd52f7637d46dddc92dda86aa5f Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Tue, 2 Jan 2024 20:31:27 +0900 Subject: [PATCH] Fix coverity issue - Data race condition [Version] 0.4.118 [Issue Type] Coverity Change-Id: I78d51b1e3b467c3e52799d36568a511a29960564 Signed-off-by: Jeongmo Yang --- packaging/capi-media-camera.spec | 2 +- src/camera.c | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index ac211a6..2c01ab2 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: 0.4.117 +Version: 0.4.118 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index 66861d1..ecd9e82 100644 --- a/src/camera.c +++ b/src/camera.c @@ -473,24 +473,43 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv * 2. EVAS display rendering * 3. media bridge is set */ + + g_mutex_lock(&cb_info->bridge_lock); + if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] || cb_info->is_evas_render || cb_info->bridge) { ret = __camera_create_media_packet_data(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data); if (ret != CAMERA_ERROR_NONE) { + g_mutex_unlock(&cb_info->bridge_lock); CAM_LOG_ERROR("__camera_create_media_packet_data failed[0x%x]", ret); goto _PREVIEW_CB_HANDLER_DONE; } ret = __camera_create_media_packet(cb_info, stream, mp_data, &pkt); if (ret != CAMERA_ERROR_NONE) { + g_mutex_unlock(&cb_info->bridge_lock); CAM_LOG_ERROR("__camera_create_media_packet failed[0x%x]", ret); __camera_release_media_packet_data(mp_data, cb_info); mp_data = NULL; goto _PREVIEW_CB_HANDLER_DONE; } + +//LCOV_EXCL_START + /* 3. media bridge */ + if (cb_info->bridge) { + media_packet_ref(pkt); + ret = media_bridge_push_packet(cb_info->bridge, pkt); + if (ret != MEDIA_BRIDGE_ERROR_NONE) { + CAM_LOG_ERROR("push packet to bridge failed[0x%x]", ret); + media_packet_unref(pkt); + } + } +//LCOV_EXCL_STOP } + g_mutex_unlock(&cb_info->bridge_lock); + /* 1. media packet preview callback */ if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) { media_packet_ref(pkt); @@ -518,22 +537,6 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv } } -//LCOV_EXCL_START - /* 3. media bridge */ - g_mutex_lock(&cb_info->bridge_lock); - - if (cb_info->bridge) { - media_packet_ref(pkt); - ret = media_bridge_push_packet(cb_info->bridge, pkt); - if (ret != MEDIA_BRIDGE_ERROR_NONE) { - CAM_LOG_ERROR("push packet to bridge failed[0x%x]", ret); - media_packet_unref(pkt); - } - } -//LCOV_EXCL_STOP - - g_mutex_unlock(&cb_info->bridge_lock); - _PREVIEW_CB_HANDLER_DONE: /* send PREVIEW_CB_RETURN message if zero copy buffer is used(num_buffer_fd is bigger than 0) and preview callback(normal or media packet) is set. */ -- 2.7.4