Initialize fd to -1 for muse_camera_export_data 62/241262/2 accepted/tizen/unified/20200820.034821 submit/tizen/20200819.022508 submit/tizen/20200819.121427
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 19 Aug 2020 00:43:38 +0000 (09:43 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 19 Aug 2020 01:24:10 +0000 (10:24 +0900)
- fd 0 which is not imported could be closed when free export data,
  then, it will cause invalid fd operation.

[Version] 0.3.34
[Issue Type] Bug fix

Change-Id: Idad72d74abd4c66daa960c34b9804b9c5271e262
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
muse/include/muse_camera_internal.h
muse/src/muse_camera_dispatcher.c
packaging/mmsvc-camera.spec

index f559d38..68546d2 100644 (file)
@@ -82,7 +82,7 @@ typedef struct {
 } muse_camera_handle_s;
 
 
-muse_camera_export_data *camera_export_data_new(MMCamcorderVideoStreamDataType *stream,
+muse_camera_export_data *camera_export_data_new_from_stream(MMCamcorderVideoStreamDataType *stream,
        tbm_bufmgr bufmgr, tbm_fd tfd[MUSE_NUM_FD]);
 void camera_export_data_free(gpointer data);
 gboolean camera_remove_export_data(muse_camera_data_list *data_list, tbm_fd fd);
index 271d024..35a552b 100644 (file)
                } \
        } while (0)
 
+static muse_camera_export_data *__camera_export_data_new(void)
+{
+       int i = 0;
+       muse_camera_export_data *new_data = g_new0(muse_camera_export_data, 1);
+
+       new_data->fd = -1;
+       new_data->data_fd = -1;
+       for (i = 0 ; i < MUSE_NUM_FD ; i++)
+               new_data->buffer_fd[i] = -1;
+
+       return new_data;
+}
+
 static void __camera_dispatcher_send_msg(muse_module_h module, char *msg, int *tfd)
 {
        int len = 0;
@@ -526,8 +539,10 @@ void camera_export_data_free(gpointer data)
        /* close exported fd for zero copy buffer */
        for (i = 0 ; i < export_data->num_buffer_fd ; i++) {
                /*LOGD("close export_data->buffer_fd[%d] %d", i, export_data->buffer_fd[i]);*/
-               close(export_data->buffer_fd[i]);
-               export_data->buffer_fd[i] = -1;
+               if (export_data->buffer_fd[i] > -1) {
+                       close(export_data->buffer_fd[i]);
+                       export_data->buffer_fd[i] = -1;
+               }
        }
 
        /* unref GstBuffer */
@@ -615,7 +630,7 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da
        camera_return_if_fail(muse_camera && image);
 
        /* main image */
-       export_data_main = g_new0(muse_camera_export_data, 1);
+       export_data_main = __camera_export_data_new();
 
        data_size_main = sizeof(camera_image_data_s) + image->size;
        if (image->exif && image->exif_size > 0)
@@ -663,11 +678,7 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da
        if (postview && postview->size > 0) {
                data_size_post = sizeof(camera_image_data_s) + postview->size;
 
-               export_data_post = g_new0(muse_camera_export_data, 1);
-               if (export_data_post == NULL) {
-                       LOGE("alloc export_data failed");
-                       goto postview_image_error;
-               }
+               export_data_post = __camera_export_data_new();
 
                /* alloc bo */
                bo_post = tbm_bo_alloc(muse_camera->bufmgr, data_size_post, TBM_BO_DEFAULT);
@@ -704,11 +715,7 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da
        if (thumbnail && thumbnail->size > 0) {
                data_size_thumb = sizeof(camera_image_data_s) + thumbnail->size;
 
-               export_data_thumb = g_new0(muse_camera_export_data, 1);
-               if (export_data_thumb == NULL) {
-                       LOGE("alloc export_data failed");
-                       goto thumbnail_image_error;
-               }
+               export_data_thumb = __camera_export_data_new();
 
                /* alloc bo */
                bo_thumb = tbm_bo_alloc(muse_camera->bufmgr, data_size_thumb, TBM_BO_DEFAULT);
@@ -907,7 +914,7 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void
        muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module);
        camera_return_if_fail(muse_camera);
 
-       export_data = camera_export_data_new(stream, muse_camera->bufmgr, tfd);
+       export_data = camera_export_data_new_from_stream(stream, muse_camera->bufmgr, tfd);
        camera_return_if_fail(export_data);
 
        /* add bo info to list */
@@ -983,7 +990,7 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun
 
                camera_return_if_fail(muse_camera);
 
-               export_data = g_new0(muse_camera_export_data, 1);
+               export_data = __camera_export_data_new();
 
                bo = tbm_bo_alloc(muse_camera->bufmgr, bo_size, TBM_BO_DEFAULT);
                if (bo == NULL) {
@@ -5156,7 +5163,7 @@ static tbm_bo __camera_normal_buffer_bo_new(MMCamcorderVideoStreamDataType *stre
 }
 
 
-muse_camera_export_data *camera_export_data_new(MMCamcorderVideoStreamDataType *stream, tbm_bufmgr bufmgr, tbm_fd tfd[MUSE_NUM_FD])
+muse_camera_export_data *camera_export_data_new_from_stream(MMCamcorderVideoStreamDataType *stream, tbm_bufmgr bufmgr, tbm_fd tfd[MUSE_NUM_FD])
 {
        /* tfd[MUSE_NUM_FD]
           0: MMCamcorderVideoStreamDataType
@@ -5173,9 +5180,7 @@ muse_camera_export_data *camera_export_data_new(MMCamcorderVideoStreamDataType *
 
        /*LOGD("Enter");*/
 
-       export_data = g_new0(muse_camera_export_data, 1);
-       export_data->fd = -1;
-       export_data->data_fd = -1;
+       export_data = __camera_export_data_new();
 
        export_data->bo = tbm_bo_alloc(bufmgr, sizeof(MMCamcorderVideoStreamDataType), TBM_BO_DEFAULT);
        if (export_data->bo == NULL) {
index d0987b0..ebb4c4b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-camera
 Summary:    A Camera module for muse server
-Version:    0.3.33
+Version:    0.3.34
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0