Fix SVACE Issues and apply tizen coding rule 37/121837/4
authorHaejeong Kim <backto.kim@samsung.com>
Wed, 29 Mar 2017 07:14:05 +0000 (16:14 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Wed, 29 Mar 2017 07:59:24 +0000 (16:59 +0900)
Change-Id: Ifb12bda2b5733836ff4a9cb5e088fca2f738cb4e

packaging/media-server.spec
src/common/media-common-db-svc.c
src/common/media-common-system.c
src/mediadb-update.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c

index cd5a167..cfdc70a 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.3.32
+Version:    0.3.33
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index 5932f52..bf6b57e 100755 (executable)
@@ -224,6 +224,10 @@ int ms_load_functions(void)
                };
        /*init array for adding name of so*/
        so_array = g_array_new(FALSE, FALSE, sizeof(char*));
+       if (so_array == NULL) {
+               MS_DBG_ERR("g_array_new failed");
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
+       }
 
        /*load information of so*/
        _ms_load_config();
index a1b7a81..6a71078 100755 (executable)
@@ -421,7 +421,7 @@ int ms_sys_get_device_list(ms_stg_type_e stg_type, GArray **dev_list)
                        for (i = 0; i < count; i++) {
                                if (i == 0) {
                                        err = usb_device_list_get_first(list, &device);
-                                       if(err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
+                                       if (err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
                                                mount_path = usb_device_get_mountpath(device);
                                                if (mount_path != NULL) {
                                                        MS_DBG_WARN("mount_path [%s]", mount_path);
@@ -429,7 +429,7 @@ int ms_sys_get_device_list(ms_stg_type_e stg_type, GArray **dev_list)
                                        }
                                } else {
                                        usb_device_list_get_next(list, &device);
-                                       if(device != NULL) {
+                                       if (device != NULL) {
                                                mount_path = usb_device_get_mountpath(device);
                                                if (mount_path != NULL) {
                                                        MS_DBG_WARN("mount_path [%s]", mount_path);
@@ -471,10 +471,13 @@ int ms_sys_release_device_list(GArray **dev_list)
                        ms_block_info_s *data = NULL;
                        data = g_array_index(*dev_list , ms_block_info_s*, 0);
                        g_array_remove_index(*dev_list, 0);
-                       MS_DBG("MOUNT PATH [%s] RELEASED", data->mount_path);
-                       MS_SAFE_FREE(data->mount_path);
-                       MS_SAFE_FREE(data->mount_uuid);
-                       MS_SAFE_FREE(data);
+
+                       if (data != NULL) {
+                               MS_DBG("MOUNT PATH [%s] RELEASED", data->mount_path);
+                               MS_SAFE_FREE(data->mount_path);
+                               MS_SAFE_FREE(data->mount_uuid);
+                               MS_SAFE_FREE(data);
+                       }
                }
                g_array_free(*dev_list, FALSE);
                *dev_list = NULL;
index 05b184c..e061c56 100755 (executable)
 #define DEVICE_MMC "mmc"
 #define DEVICE_ALL "all"
 
-#define MU_SAFE_FREE(src)              { if (src) {free(src); src = NULL;} }
+#define MU_SAFE_FREE(src)              { if (src) {free(src); src = NULL; } }
 
 
 GMainLoop * mainloop = NULL;
 
-typedef struct block_info_s{
+typedef struct block_info_s {
        char *mount_path;
        int state;
        int block_type;
@@ -229,9 +229,11 @@ void __release_device_list(GArray **dev_list)
                        block_info_s *data = NULL;
                        data = g_array_index(*dev_list , block_info_s*, 0);
                        g_array_remove_index(*dev_list, 0);
-                       MU_SAFE_FREE(data->mount_path);
-                       MU_SAFE_FREE(data->mount_uuid);
-                       MU_SAFE_FREE(data);
+                       if (data != NULL) {
+                               MU_SAFE_FREE(data->mount_path);
+                               MU_SAFE_FREE(data->mount_uuid);
+                               MU_SAFE_FREE(data);
+                       }
                }
                g_array_free(*dev_list, FALSE);
                *dev_list = NULL;
index 9e7b645..6168edc 100755 (executable)
@@ -206,7 +206,7 @@ static int __msc_check_stop_status(int scan_type, ms_storage_type_t storage_type
                if ((cancel_scan_item != NULL) && (cancel_scan_item->path != NULL)) {
                        MS_DBG_WARN("check blocked storage [%s][%s]", cancel_scan_item->path, start_path);
                        if ((strncmp(cancel_scan_item->path, start_path, strlen(cancel_scan_item->path)) == 0)
-                               && (cancel_scan_item->pid == -1 || cancel_scan_item->pid == pid)){
+                               && (cancel_scan_item->pid == -1 || cancel_scan_item->pid == pid)) {
                                MS_DBG_ERR("Receive cancel request [%s][%s]. STOP scan!!", cancel_scan_item->path, start_path);
                                unsigned int path_len = strlen(cancel_scan_item->path);
 
@@ -319,7 +319,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, pid);
                /* get the current path from directory array */
                current_path = g_array_index(dir_array , char*, 0);
-               g_array_remove_index (dir_array, 0);
+               g_array_remove_index(dir_array, 0);
 
                __msc_set_dir_scan_cur_path(current_path);
 
@@ -439,7 +439,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                }
 
                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, d->d_name) != MS_MEDIA_ERR_NONE) {
-                                       MS_DBG_ERR("ms_strappend failed");
+                                       MS_DBG_ERR("ms_strappend failed");
                                        bpos += d->d_reclen;
                                        continue;
                                }
@@ -463,7 +463,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                        }
 
                                        /* insert into media DB */
-                                       ret = ms_scan_validate_item(handle,storage_id, path, uid);
+                                       ret = ms_scan_validate_item(handle, storage_id, path, uid);
                                        if (ret != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db : %d\n", scan_type);
                                                if (ret == MS_MEDIA_ERR_FILE_IO) {
@@ -546,7 +546,7 @@ STOP_SCAN:
        ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_STOP, uid);
 
 END_SCAN:
-       if(fd != -1) {
+       if (fd != -1) {
                close(fd);
                fd = -1;
        }
@@ -763,12 +763,12 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                                                continue;
                                        }
                                        /* insert into media DB */
-                                       ret = scan_function(handle,storage_id, path, uid);
+                                       ret = scan_function(handle, storage_id, path, uid);
                                        if (ret != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db : %d\n", scan_type);
                                                if (ret == MS_MEDIA_ERR_FILE_IO) {
                                                        MS_DBG_ERR("I/O ERROR COUNT[%d]", io_err_storage++);
-                                               }       
+                                               }
                                                bpos += d->d_reclen;
                                                continue;
                                        } else {
@@ -1228,7 +1228,7 @@ gboolean msc_directory_scan_thread(void *data)
                                                }
 
                                                ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
-                                               if ((scan_status == MS_DIR_SCAN_DONE ) || (scan_status == MS_DIR_SCAN_STOP)) {
+                                               if ((scan_status == MS_DIR_SCAN_DONE) || (scan_status == MS_DIR_SCAN_STOP)) {
                                                        MS_DBG_WARN("[%s] scan status [%d]!!!", scan_data->msg, scan_status);
                                                        break;
                                                }
@@ -1297,7 +1297,7 @@ gboolean msc_directory_scan_thread(void *data)
 
                        /*remove invalid folder in folder table.*/
                        if (is_recursive == true) {
-                               if(ms_delete_invalid_folder_by_path(handle, storage_id, scan_data->msg, uid, &delete_folder_count) != MS_MEDIA_ERR_NONE) {
+                               if (ms_delete_invalid_folder_by_path(handle, storage_id, scan_data->msg, uid, &delete_folder_count) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("deleting invalid folder failed");
                                }
                        }
@@ -1524,8 +1524,10 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
                ms_dir_info_s *data = NULL;
                data = g_array_index(dir_array , ms_dir_info_s*, 0);
                g_array_remove_index(dir_array, 0);
-               MS_SAFE_FREE(data->dir_path);
-               MS_SAFE_FREE(data);
+               if (data != NULL) {
+                       MS_SAFE_FREE(data->dir_path);
+                       MS_SAFE_FREE(data);
+               }
        }
        g_array_free(dir_array, FALSE);
        dir_array = NULL;
@@ -1543,10 +1545,10 @@ int __msc_check_pvr_svc()
 #ifdef _USE_RECORDED_CONTENT
        if (ms_is_support_pvr()) {
                while (1) {
-                       FILE* file = fopen( "/run/pvr_ready", "rb" );
+                       FILE* file = fopen("/run/pvr_ready", "rb");
 
                        if (file != NULL) {
-                               fclose( file );
+                               fclose(file);
                                MS_DBG_WARN("PVR service is ready");
                                break;
                        } else {
@@ -1651,7 +1653,7 @@ gboolean msc_storage_scan_thread(void *data)
                                if (!ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, uid)) {
                                        MS_DBG_ERR("ms_delete_invalid_items fails");
                                }
-                       }/* else if (scan_type == MS_MSG_STORAGE_PARTIAL) {
+                       } /* else if (scan_type == MS_MSG_STORAGE_PARTIAL) {
                                        ms_validaty_change_all_items(handle, scan_data->storage_id, storage_type, false, uid);
                        }*/
 
@@ -1996,7 +1998,7 @@ int _msc_set_scan_item(s_scan_item** item, const char* path, int pid)
                scan_item->pid = -1;
        } else {
                scan_item = (s_scan_item*)malloc(sizeof(s_scan_item));
-               if(scan_item == NULL) {
+               if (scan_item == NULL) {
                        MS_DBG_ERR("malloc item failed...");
                        return MS_MEDIA_ERR_INTERNAL;
                }
@@ -2026,12 +2028,12 @@ int msc_set_cancel_scan_item(const char* cancel_path, int pid)
        int ret = -1;
        MS_DBG_WARN("msc_set_cancel_scan_item begin");
        g_mutex_lock(&scan_item_mutex);
-       if(cancel_path == NULL) {
+       if (cancel_path == NULL) {
                MS_DBG_ERR("cancel_path invalid...");
                return ret;
        }
 
-       if(cur_scan_item != NULL && cur_scan_item->path != NULL) {
+       if (cur_scan_item != NULL && cur_scan_item->path != NULL) {
                MS_DBG_WARN("cur_scan_item->path[%s], cur_scan_item->pid[%d]", cur_scan_item->path, cur_scan_item->pid);
                MS_DBG_WARN("cancel_path[%s], pid[%d]", cancel_path, pid);
                if ((strcmp(cur_scan_item->path, cancel_path) == 0) && (pid == cur_scan_item->pid)) {
@@ -2206,19 +2208,19 @@ int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
        int ret = MS_MEDIA_ERR_NONE;
 
        switch (scan_type) {
-               case MS_SCAN_STORAGE:
-                       g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
-                       break;
-               case MS_SCAN_DIRECTORY:
-                       g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
-                       break;
-               case MS_SCAN_REGISTER:
-                       g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
-                       break;
-               default:
-                       MS_DBG_ERR("invalid parameter");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       break;
+       case MS_SCAN_STORAGE:
+               g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
+               break;
+       case MS_SCAN_DIRECTORY:
+               g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
+               break;
+       case MS_SCAN_REGISTER:
+               g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
+               break;
+       default:
+               MS_DBG_ERR("invalid parameter");
+               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+               break;
        }
 
        return ret;
@@ -2271,19 +2273,19 @@ int msc_get_remain_scan_request(ms_scan_type_e scan_type, int *remain_request)
        int ret = MS_MEDIA_ERR_NONE;
 
        switch (scan_type) {
-               case MS_SCAN_STORAGE:
-                       *remain_request = g_async_queue_length(storage_queue2);
-                       break;
-               case MS_SCAN_DIRECTORY:
-                       *remain_request = g_async_queue_length(scan_queue2);
-                       break;
-               case MS_SCAN_REGISTER:
-                       *remain_request = g_async_queue_length(reg_queue2);
-                       break;
-               default:
-                       MS_DBG_ERR("invalid parameter");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       break;
+       case MS_SCAN_STORAGE:
+               *remain_request = g_async_queue_length(storage_queue2);
+               break;
+       case MS_SCAN_DIRECTORY:
+               *remain_request = g_async_queue_length(scan_queue2);
+               break;
+       case MS_SCAN_REGISTER:
+               *remain_request = g_async_queue_length(reg_queue2);
+               break;
+       default:
+               MS_DBG_ERR("invalid parameter");
+               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+               break;
        }
 
        return ret;
index f355aed..9f8f687 100755 (executable)
@@ -811,8 +811,10 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
                ms_dir_info_s *data = NULL;
                data = g_array_index(dir_array , ms_dir_info_s*, 0);
                g_array_remove_index(dir_array, 0);
-               MS_SAFE_FREE(data->dir_path);
-               MS_SAFE_FREE(data);
+               if (data != NULL) {
+                       MS_SAFE_FREE(data->dir_path);
+                       MS_SAFE_FREE(data);
+               }
        }
        g_array_free(dir_array, FALSE);
        dir_array = NULL;
@@ -1520,19 +1522,19 @@ int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
        int ret = MS_MEDIA_ERR_NONE;
 
        switch (scan_type) {
-               case MS_SCAN_STORAGE:
-                       g_async_queue_push(storage_queue, GINT_TO_POINTER(recv_msg));
-                       break;
-               case MS_SCAN_DIRECTORY:
-                       g_async_queue_push(scan_queue, GINT_TO_POINTER(recv_msg));
-                       break;
-               case MS_SCAN_REGISTER:
-                       g_async_queue_push(reg_queue, GINT_TO_POINTER(recv_msg));
-                       break;
-               default:
-                       MS_DBG_ERR("invalid parameter");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       break;
+       case MS_SCAN_STORAGE:
+               g_async_queue_push(storage_queue, GINT_TO_POINTER(recv_msg));
+               break;
+       case MS_SCAN_DIRECTORY:
+               g_async_queue_push(scan_queue, GINT_TO_POINTER(recv_msg));
+               break;
+       case MS_SCAN_REGISTER:
+               g_async_queue_push(reg_queue, GINT_TO_POINTER(recv_msg));
+               break;
+       default:
+               MS_DBG_ERR("invalid parameter");
+               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+               break;
        }
 
        return ret;