Remove out of memory related code by using glib APIs 47/230647/12
authorhj kim <backto.kim@samsung.com>
Mon, 13 Apr 2020 07:00:56 +0000 (16:00 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 17 Apr 2020 03:40:49 +0000 (12:40 +0900)
glib's memory managed as below.
If any call to allocate memory fails, the application is terminated. This also means that there is no need to check if the call succeeded.

Change-Id: I0a47c563dda34a37d3936f94ef7f90fbfa679303

24 files changed:
lib/include/media-util-internal.h
lib/media-util-cynara.c
lib/media-util-db.c
lib/media-util-dcm.c
lib/media-util-register.c [changed mode: 0755->0644]
lib/media-util-user.c
src/common/include/media-common-types.h
src/common/media-common-db-svc.c
src/common/media-common-external-storage.c
src/common/media-common-system.c
src/common/media-common-utils.c
src/mediadb-update.c
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner-v2/media-scanner-socket-v2.c
src/scanner-v2/media-scanner-v2.c
src/scanner/media-scanner-scan.c
src/scanner/media-scanner-socket.c
src/server/media-server-db-manage.c
src/server/media-server-dcm.c
src/server/media-server-device-block.c
src/server/media-server-main.c
src/server/media-server-socket.c
src/server/media-server-thumb.c

index 5579677..491223c 100755 (executable)
@@ -28,9 +28,6 @@
 #include "media-util-db.h"
 
 #define MS_SAFE_FREE(src)              { if (src) {free(src); src = NULL; } }
-#define MS_MALLOC(src, size)   { if (size > SIZE_MAX || size <= 0) src = NULL; \
-                                                       else { src = malloc(size); if (src) memset(src, 0x0, size); } }
-
 #define MS_SQL_SAFE_FREE(x)    {if (x != NULL) {sqlite3_free(x); x = NULL; } }
 #define MS_STRING_VALID(str)   ((str != NULL && strlen(str) > 0) ? true : false)
 #define SAFE_STRLCPY(dst, src, n)      g_strlcpy(dst, src, n);
index 1068744..bf2b877 100755 (executable)
@@ -139,11 +139,11 @@ int ms_cynara_receive_untrusted_message_thumb(int sockfd, thumbMsg *recv_msg, ms
                return MS_MEDIA_ERR_INVALID_PARAMETER;
 
        header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
-       MS_MALLOC(buf, header_size);
+       buf = g_malloc0(header_size);
 
        if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
                MSAPI_DBG_STRERROR("recv failed");
-               MS_SAFE_FREE(buf);
+               g_free(buf);
                return MS_MEDIA_ERR_IPC;
        }
 
index 59f1307..94bd756 100755 (executable)
@@ -142,11 +142,11 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo
 
        if (SQLITE_OK != ret) {
                MSAPI_DBG_ERR("error when db open path[%s],ret[%d]", db_path, ret);
-               MS_SAFE_FREE(db_path);
+               g_free(db_path);
                *db_handle = NULL;
                return MS_MEDIA_ERR_DB_INTERNAL;
        }
-       MS_SAFE_FREE(db_path);
+       g_free(db_path);
 
        if (*db_handle == NULL) {
                MSAPI_DBG_ERR("*db_handle is NULL");
@@ -421,7 +421,7 @@ static int __media_db_request_recovery(uid_t uid)
        MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PARAMETER, "ms_user_get_media_db_path failed");
 
        if (!ms_ipc_is_valid_msg(db_path)) {
-               MS_SAFE_FREE(db_path);
+               g_free(db_path);
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
@@ -430,7 +430,7 @@ static int __media_db_request_recovery(uid_t uid)
 
        send_msg.msg_type = MS_MSG_MEDIA_DB_MALFORMED;
        SAFE_STRLCPY(send_msg.msg, db_path, sizeof(send_msg.msg));
-       MS_SAFE_FREE(db_path);
+       g_free(db_path);
        send_msg.uid = uid;
 
        /*Create Socket*/
index 3f056e0..4531918 100755 (executable)
@@ -79,9 +79,9 @@ static void __media_dcm_pop_data(void)
                if (source_id)
                        g_source_destroy(source_id);
 
-               MS_SAFE_FREE(req->path);
-               MS_SAFE_FREE(req->userData);
-               MS_SAFE_FREE(req);
+               g_free(req->path);
+               g_free(req->userData);
+               g_free(req);
        }
 
        len = g_queue_get_length(g_manage_queue);
@@ -107,9 +107,9 @@ static int __media_dcm_cancel_data(int request_id)
                                req->isCanceled = true;
                        } else {
                                g_queue_pop_nth(g_manage_queue, i);
-                               MS_SAFE_FREE(req->path);
-                               MS_SAFE_FREE(req->userData);
-                               MS_SAFE_FREE(req);
+                               g_free(req->path);
+                               g_free(req->userData);
+                               g_free(req);
                        }
                        return MS_MEDIA_ERR_NONE;
                }
@@ -242,7 +242,6 @@ static int __media_dcm_send_request(void)
 
 static int __media_dcm_request_async(int msg_type, const unsigned int request_id, const char *path, faceUserData *userData, uid_t uid)
 {
-       int len = 0;
        dcmReq *dcm_req = NULL;
 
        if (msg_type == DCM_MSG_REQUEST_CANCEL_FACE)
@@ -251,8 +250,7 @@ static int __media_dcm_request_async(int msg_type, const unsigned int request_id
        if (!g_manage_queue)
                g_manage_queue = g_queue_new();
 
-       dcm_req = calloc(1, sizeof(dcmReq));
-       MSAPI_RETV_IF(!dcm_req, MS_MEDIA_ERR_OUT_OF_MEMORY);
+       dcm_req = g_new0(dcmReq, 1);
 
        dcm_req->msg_type = msg_type;
        dcm_req->path = g_strdup(path);
@@ -262,11 +260,10 @@ static int __media_dcm_request_async(int msg_type, const unsigned int request_id
        dcm_req->uid = uid;
 
        MSAPI_DBG("Enqueue");
-       len = g_queue_get_length(g_manage_queue);
        g_queue_push_tail(g_manage_queue, (gpointer)dcm_req);
 
        /* directly request at first time */
-       if (len == 0)
+       if (g_queue_get_length(g_manage_queue) == 1)
                return __media_dcm_send_request();
 
        return MS_MEDIA_ERR_NONE;
@@ -276,6 +273,7 @@ int dcm_request_extract_face_async(const unsigned int request_id, const char *pa
 {
        int exist = -1;
        ms_user_storage_type_e storage_type = -1;
+       faceUserData *userData = NULL;
 
        MSAPI_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
 
@@ -298,8 +296,7 @@ int dcm_request_extract_face_async(const unsigned int request_id, const char *pa
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       faceUserData *userData = (faceUserData*)malloc(sizeof(faceUserData));
-       MSAPI_RETV_IF(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY);
+       userData = g_new0(faceUserData, 1);
 
        userData->func = (FaceFunc)func;
        userData->user_data = user_data;
old mode 100755 (executable)
new mode 100644 (file)
index 100dc0e..d3b0da3 100755 (executable)
@@ -153,7 +153,6 @@ int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_e
 
        ret = ms_user_get_internal_root_path(uid, &internal_path);
        MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail get internal root path");
-       MSAPI_RETVM_IF(internal_path == NULL, ret, "Fail get internal root path (NULL)");
 
        path_len = strlen(internal_path);
 
@@ -170,7 +169,7 @@ int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_e
                ret = MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       MS_SAFE_FREE(internal_path);
+       g_free(internal_path);
 
        return ret;
 }
index 87daf53..c04f3d4 100755 (executable)
@@ -60,8 +60,6 @@ typedef enum {
 #define POWEROFF -1 /*This number uses for stopping Scannig thread*/
 
 #define MS_SAFE_FREE(src)              { if (src) {free(src); src = NULL; } }
-#define MS_MALLOC(src, size)   { if (size > SIZE_MAX || size <= 0) src = NULL; \
-                                                       else { src = malloc(size); if (src) memset(src, 0x0, size); } }
 #define MS_STRING_VALID(str)   \
                                                                ((str != NULL && strlen(str) > 0) ? true : false)
 #define SAFE_STRLCPY(dst, src, n)      g_strlcpy(dst, src, n);
index c739d79..346f74e 100644 (file)
@@ -134,7 +134,7 @@ int ms_load_functions(void)
                func_array[func_index] = dlsym(func_handle, func_list[func_index]);
                if (func_array[func_index] == NULL) {
                        MS_DBG_ERR("dlsym failed[%s]", func_list[func_index]);
-                       MS_SAFE_FREE(func_array);
+                       g_free(func_array);
                        dlclose(func_handle);
 
                        return MS_MEDIA_ERR_INTERNAL;
@@ -233,7 +233,7 @@ static int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const
                                char* folder_path = NULL;
                                folder_path = g_path_get_dirname(path);
                                ret = ms_get_folder_id(handle, storage_id, folder_path, &folder_id_folder);
-                               MS_SAFE_FREE(folder_path);
+                               g_free(folder_path);
                                if(ret == MS_MEDIA_ERR_NONE) {
                                        if (g_strcmp0(folder_id_media, folder_id_folder) == 0)
                                                *modified = false;
@@ -242,7 +242,7 @@ static int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const
                                } else
                                        *modified = true;
 
-                               MS_SAFE_FREE(folder_id_folder);
+                               g_free(folder_id_folder);
 #endif
                        }
                }
@@ -820,21 +820,17 @@ int ms_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, const
 {
        int ret = MS_MEDIA_ERR_NONE;
        char **folder_list = NULL;
-       char *sub_path = NULL;
        int count = 0;
        int i = 0;
 
        ret = ((GET_NULL_SCAN_FOLDER_LIST)func_array[eGET_NULL_SCAN_FOLDER_LIST])(handle, stroage_id, path, &folder_list, &count); /*dlopen*/
        MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_NULL_SCAN_FOLDER_LIST failed [%d]", ret);
 
-       *dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
-       if (count != 0) {
-               for (i = 0; i < count; i++) {
-                       sub_path = strdup(folder_list[i]);
-                       g_array_append_val(*dir_array, sub_path);
-                       MS_SAFE_FREE(folder_list[i]);
-               }
-       }
+       *dir_array = g_array_sized_new(FALSE, FALSE, sizeof(char*), count);
+
+       for (i = 0; i < count; i++)
+               g_array_append_val(*dir_array, folder_list[i]);
+
 
        MS_SAFE_FREE(folder_list);
 
index 014d55d..70b7f9d 100755 (executable)
@@ -61,7 +61,7 @@ int ms_read_device_info(const char *root_path, char **device_uuid)
                                MS_DBG_WARN("FIND DEV INFO : %s", name);
                                len = strlen(name + strlen(DEVICE_INFO_FILE));
                                if (len > 0) {
-                                       *device_uuid = strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
+                                       *device_uuid = g_strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
                                        MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
                                }
 
@@ -144,13 +144,13 @@ int ms_get_added_storage_path(const char *add_path, char **device_id)
                        ret = ms_genarate_uuid(&id);
                        ret = ms_write_device_info(add_path , id);
                        if (ret == MS_MEDIA_ERR_NONE)
-                               *device_id = strdup(id);
+                               *device_id = g_strdup(id);
                }
        } else {
-               *device_id = strdup(id);
+               *device_id = g_strdup(id);
        }
 
-       MS_SAFE_FREE(id);
+       g_free(id);
 
        return ret;
 }
index 3bf0622..74fd949 100644 (file)
@@ -375,7 +375,7 @@ static void __poweroff_signal_cb(GDBusConnection *connection,
                return ;
        }
 
-       type_str = strdup((char *)g_variant_get_type_string(parameters));
+       type_str = g_strdup((char *)g_variant_get_type_string(parameters));
        if (!type_str) {
                MS_DBG_ERR("Failed to get the type-string of message");
                return ;
@@ -394,7 +394,7 @@ static void __poweroff_signal_cb(GDBusConnection *connection,
        if (val_int == 2 || val_int == 3)
                cb_func(usr_data);
 
-       MS_SAFE_FREE(type_str);
+       g_free(type_str);
 }
 
 int ms_sys_set_poweroff_cb(power_off_cb user_callback, void *user_data)
index c156ef6..8fd149f 100644 (file)
@@ -108,7 +108,7 @@ bool ms_config_get_str(const char *key, char **value)
 
        res = vconf_get_str(key);
        if (MS_STRING_VALID(res)) {
-               *value = strdup(res);
+               *value = g_strdup(res);
                MS_SAFE_FREE(res);
                return true;
        }
@@ -204,14 +204,14 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
        dir_path = g_path_get_dirname(full_path);
        if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
                MS_DBG_ERR("getting directory path is failed : %s", full_path);
-               MS_SAFE_FREE(dir_path);
+               g_free(dir_path);
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
        ret = ms_user_get_internal_root_path(uid, &usr_path);
        if (ret != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("ms_user_get_internal_root_path() fail");
-               MS_SAFE_FREE(dir_path);
+               g_free(dir_path);
                return MS_MEDIA_ERR_INTERNAL;
        }
 
@@ -247,19 +247,18 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
                }
        }
 
-       MS_SAFE_FREE(dir_path);
-       MS_SAFE_FREE(usr_path);
+       g_free(dir_path);
+       g_free(usr_path);
 
        return ret;
 }
 
 static void __ms_trim_path(const char *input_path, char **output_path)
 {
-       char buf[4096] = {0,};
-       char tmp[4096] = {0,};
+       char buf[4096] = {0, };
+       char tmp[4096] = {0, };
        char *pos = NULL;
 
-       memset(buf, 0, sizeof(buf));
        SAFE_STRLCPY(buf, input_path, sizeof(buf));
 
        while ((pos = strstr(buf, "//")) != NULL) {
@@ -298,7 +297,7 @@ int ms_check_scan_ignore(char * path, uid_t uid)
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(tmp_path, org_path) != 0) {
                MS_SAFE_FREE(tmp_path);
-               MS_SAFE_FREE(org_path);
+               g_free(org_path);
                MS_DBG_ERR("symbolic link(directory)");
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
@@ -309,24 +308,23 @@ int ms_check_scan_ignore(char * path, uid_t uid)
                MS_SAFE_FREE(mediashared);
                if (g_strcmp0(replace, org_path) != 0) {
                        MS_SAFE_FREE(tmp_path);
-                       MS_SAFE_FREE(org_path);
+                       g_free(org_path);
                        MS_DBG_ERR("symbolic link(directory)");
                        return MS_MEDIA_ERR_INVALID_PARAMETER;
                }
        } else {
                if (g_strcmp0(tmp_path, org_path) != 0) {
                        MS_SAFE_FREE(tmp_path);
-                       MS_SAFE_FREE(org_path);
+                       g_free(org_path);
                        MS_DBG_ERR("symbolic link(directory)");
                        return MS_MEDIA_ERR_INVALID_PARAMETER;
                }
        }
 #endif
        MS_SAFE_FREE(tmp_path);
-       MS_SAFE_FREE(org_path);
+       g_free(org_path);
 
        if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
-               memset(ignore_path, 0, sizeof(ignore_path));
                snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
 
                if (g_file_test(ignore_path, G_FILE_TEST_EXISTS)) {
@@ -372,7 +370,7 @@ bool ms_storage_mount_status(const char* start_path)
        if (remain_path != NULL)
                remain_len = strlen(remain_path);
 
-       storage_path = strndup(start_path, strlen(start_path) - remain_len);
+       storage_path = g_strndup(start_path, strlen(start_path) - remain_len);
 
        MS_DBG_SWARN("storage_path [%s]", storage_path);
 
@@ -418,7 +416,7 @@ bool ms_storage_mount_status(const char* start_path)
                MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
        }
 
-       MS_SAFE_FREE(storage_path);
+       g_free(storage_path);
 #endif
        return ret;
 }
@@ -504,7 +502,7 @@ int ms_check_size_mediadb(uid_t uid, double *db_size)
                ret = MS_MEDIA_ERR_INTERNAL;
        }
 
-       MS_SAFE_FREE(db_path);
+       g_free(db_path);
 
        return ret;
 }
index ade6326..787592b 100755 (executable)
@@ -163,12 +163,7 @@ int main(int argc, char **argv)
                exit(0);
        }
 
-       argv1 = strdup(argv[1]);
-       if (argv1 == NULL) {
-               printf("[%d]Internal Memory Error\n", __LINE__);
-               __print_help();
-               exit(0);
-       }
+       argv1 = argv[1];
 
        mainloop = g_main_loop_new(NULL, FALSE);
 
@@ -203,7 +198,7 @@ int main(int argc, char **argv)
                        exit(0);
                }
        } else if (argc == 3) {
-               argv2 = strdup(argv[2]);
+               argv2 = argv[2];
                if (strcmp(argv1, "-r") == 0) {
                        if ((argv2 != NULL) && (g_file_test(argv2, G_FILE_TEST_IS_DIR))) {
                                len = strlen(argv2);
index 6a411a9..7b6fe09 100644 (file)
@@ -227,7 +227,7 @@ gboolean msc_folder_extract_thread(void *data)
                scan_type = extract_data->msg_type;
                noti_type = extract_data->noti_type;
 
-               storage_id = strdup(extract_data->storage_id);
+               storage_id = g_strdup(extract_data->storage_id);
                if (storage_id == NULL) {
                        MS_DBG_ERR("storage_id NULL");
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -303,9 +303,9 @@ NEXT:
                        msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, extract_data->pid, extract_data->msg);
                }
 
-               MS_SAFE_FREE(update_path);
-               MS_SAFE_FREE(extract_data);
-               MS_SAFE_FREE(storage_id);
+               g_free(update_path);
+               g_free(extract_data);
+               g_free(storage_id);
 
                __msc_del_cur_extract_item();
                __msc_del_cancel_extract_item();
@@ -339,9 +339,9 @@ NEXT:
 _POWEROFF:
        __msc_resume_extract();
 
-       MS_SAFE_FREE(update_path);
-       MS_SAFE_FREE(extract_data);
-       MS_SAFE_FREE(storage_id);
+       g_free(update_path);
+       g_free(extract_data);
+       g_free(storage_id);
 
        if (handle) ms_disconnect_db(handle);
 
@@ -472,7 +472,7 @@ STOP_DISC:
                        }
                }
 NEXT:
-               MS_SAFE_FREE(update_path);
+               g_free(update_path);
 
                if (power_off2) {
                        MS_DBG_ERR("power off");
@@ -490,7 +490,7 @@ NEXT:
                        msc_send_result(ret, extract_data);
                }
 
-               MS_SAFE_FREE(extract_data);
+               g_free(extract_data);
 
                MS_DBG_WARN("STORAGE EXTRACT END[%d]", ret);
                usleep(SCAN_SLEEP_TIME);
@@ -505,12 +505,7 @@ _POWEROFF:
 
 void msc_insert_exactor_request(int message_type, bool ins_status, const char *storage_id, const char *path, int pid, uid_t uid, ms_noti_type_e noti_type)
 {
-       ms_comm_msg_s *extract_data = NULL;
-       MS_MALLOC(extract_data, sizeof(ms_comm_msg_s));
-       if (extract_data == NULL) {
-               MS_DBG_ERR("MS_MALLOC failed");
-               return;
-       }
+       ms_comm_msg_s *extract_data = g_new0(ms_comm_msg_s, 1);
 
        extract_data->msg_type = message_type;
        extract_data->pid = pid;
@@ -521,14 +516,14 @@ void msc_insert_exactor_request(int message_type, bool ins_status, const char *s
        SAFE_STRLCPY(extract_data->storage_id, storage_id, sizeof(extract_data->storage_id));
 
        if (message_type == MS_MSG_STORAGE_ALL || message_type == MS_MSG_STORAGE_PARTIAL || message_type == MS_MSG_STORAGE_INVALID) {
-               g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(extract_data));
+               g_async_queue_push(storage_extract_queue, extract_data);
                MS_DBG("insert to storage exactor queue. msg_type [%d]", ins_status);
        } else if (message_type == MS_MSG_DIRECTORY_SCANNING || message_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
-               g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(extract_data));
+               g_async_queue_push(folder_extract_queue, extract_data);
                MS_DBG("insert to dir exactor queue. msg_type [%d]", ins_status);
        } else {
                MS_DBG_ERR("try to insert to exactor scan with msg_type [%d]", message_type);
-               MS_SAFE_FREE(extract_data);
+               g_free(extract_data);
        }
 }
 
@@ -565,9 +560,9 @@ int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
                                msg->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
                                msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
                        }
-                       MS_SAFE_FREE(msg);
+                       g_free(msg);
                } else {
-                       g_async_queue_push(temp_queue, GINT_TO_POINTER(msg));
+                       g_async_queue_push(temp_queue, msg);
                }
        }
        len = g_async_queue_length(temp_queue);
@@ -575,7 +570,7 @@ int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
        for (j = 0; j < len; j++) {
                msg = g_async_queue_pop(temp_queue);
                if (msg)
-                       g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(msg));
+                       g_async_queue_push(storage_extract_queue, msg);
        }
        g_async_queue_unref(temp_queue);
 
@@ -590,31 +585,28 @@ END_REMOVE_REQUEST:
 static int __msc_set_extract_item(s_extract_item** item, const char* path, int pid)
 {
        s_extract_item* extract_item = *item;
-       if (extract_item != NULL) {
-               MS_SAFE_FREE(extract_item->path);
-               extract_item->pid = -1;
-       } else {
-               extract_item = (s_extract_item*)malloc(sizeof(s_extract_item));
-               if (extract_item == NULL) {
-                       MS_DBG_ERR("malloc item failed");
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-               memset(extract_item, 0, sizeof(s_extract_item));
-       }
 
-       extract_item->path = strdup(path);
+
+       if (!extract_item)
+               extract_item = g_new0(s_extract_item, 1);
+
+       g_free(extract_item->path);
+
+       extract_item->path = g_strdup(path);
        extract_item->pid = pid;
+
        *item = extract_item;
 
        MS_DBG_SWARN("__msc_set_extract_item path[%s],pid[%d]", extract_item->path, extract_item->pid);
+
        return MS_MEDIA_ERR_NONE;
 }
 
 static void __msc_del_extract_item(s_extract_item** item)
 {
        if (*item != NULL) {
-               MS_SAFE_FREE((*item)->path);
-               MS_SAFE_FREE(*item);
+               g_free((*item)->path);
+               g_free(*item);
        }
 }
 
@@ -669,7 +661,7 @@ void msc_set_extract_blocked_path(const char *blocked_path)
 
        if (g_extract_blocked_path != NULL) {
                MS_DBG_SERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
-               MS_SAFE_FREE(g_extract_blocked_path);
+               g_free(g_extract_blocked_path);
        }
 
        g_extract_blocked_path = g_strdup(blocked_path);
@@ -684,6 +676,7 @@ static void __msc_del_extract_blocked_path(const char* blocked_path)
        MS_DBG_FENTER();
 
        g_mutex_lock(&extract_blocked_mutex);
+
        if (blocked_path) {
                if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(g_extract_blocked_path)))) {
                        MS_DBG_ERR("g_extract_blocked_path is deleted  [%s]", g_extract_blocked_path);
@@ -845,20 +838,18 @@ void msc_stop_extract_thread(void)
 
        if (storage_extract_queue) {
                /*notify to storage extract thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(data));
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               g_async_queue_push(storage_extract_queue, data);
        }
 
        if (folder_extract_queue) {
                /*notify to folder extract thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(data));
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               g_async_queue_push(folder_extract_queue, data);
        }
 }
 
@@ -866,10 +857,10 @@ int msc_set_extract_cancel_path(const char *cancel_path)
 {
        if (g_extract_cancel_path != NULL) {
                MS_DBG_WARN("g_extract_cancel_path is not NULL");
-               MS_SAFE_FREE(g_extract_cancel_path);
+               g_free(g_extract_cancel_path);
        }
 
-       g_extract_cancel_path = strdup(cancel_path);
+       g_extract_cancel_path = g_strdup(cancel_path);
 
        return MS_MEDIA_ERR_NONE;
 }
index aae6393..1a4bf0a 100644 (file)
@@ -270,16 +270,8 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, co
        /* make new array for storing directory */
        dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
 
-       if (dir_array == NULL) {
-               MS_DBG_ERR("g_array_new failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
        /* add first direcotiry to directory array */
-       new_start_path = strdup(start_path);
-       if (new_start_path == NULL) {
-               MS_DBG_ERR("strdup failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
+       new_start_path = g_strdup(start_path);
 
        //MS_DBG_ERR("new start path [%s]", new_start_path);
        g_array_append_val(dir_array, start_path);
@@ -324,7 +316,7 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, co
                        ret = ms_check_scan_ignore(current_path, uid);
                        if (ret != MS_MEDIA_ERR_NONE) {
                                MS_DBG_SERR("%s is ignore", current_path);
-                               MS_SAFE_FREE(current_path);
+                               g_free(current_path);
                                if (ret == MS_MEDIA_ERR_USB_UNMOUNTED)
                                        goto STOP_SCAN;
                                else
@@ -496,17 +488,13 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, co
                                                                        ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
                                                                goto STOP_SCAN;
                                                        }
-
-
-
-
                                                }
                                        }
                                } else if (d->d_type == DT_DIR) {
                                        if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                                                /* this request is recursive scanning */
                                                /* add new directory to dir_array */
-                                               new_path = strdup(path);
+                                               new_path = g_strdup(path);
                                                g_array_append_val(dir_array, new_path);
 
                                                if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
@@ -560,7 +548,7 @@ END_SCAN:
                fd = -1;
        }
 
-       MS_SAFE_FREE(new_start_path);
+       g_free(new_start_path);
        __msc_set_dir_scan_cur_path(NULL);
 
        __msc_clear_file_list(dir_array);
@@ -600,16 +588,8 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
        /* make new array for storing directory */
        dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
 
-       if (dir_array == NULL) {
-               MS_DBG_ERR("g_array_new failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
        /* add first direcotiry to directory array */
-       new_start_path = strdup(start_path);
-       if (new_start_path == NULL) {
-               MS_DBG_ERR("strdup failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
+       new_start_path = g_strdup(start_path);
 
        g_array_append_val(dir_array, start_path);
        ms_insert_folder_end(uid);
@@ -792,7 +772,7 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
                                } else if (d->d_type == DT_DIR) {
                                        /* this request is recursive scanning */
                                        /* add new directory to dir_array */
-                                       new_path = strdup(path);
+                                       new_path = g_strdup(path);
                                        g_array_append_val(dir_array, new_path);
 
                                        if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
@@ -888,7 +868,7 @@ EXIT:
                fd = -1;
        }
 
-       MS_SAFE_FREE(new_start_path);
+       g_free(new_start_path);
        __msc_set_storage_scan_cur_path(NULL);
        __msc_clear_file_list(dir_array);
 
@@ -915,9 +895,9 @@ static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_
                        g_array_remove_index(cur_dir_array, 0);
                        MS_DBG_SLOG("current_path = [%s]", current_path);
 
-                       new_path = strdup(current_path);
+                       new_path = g_strdup(current_path);
                        g_array_append_val(dir_array, new_path);
-                       MS_SAFE_FREE(current_path);
+                       g_free(current_path);
                }
        }
 
@@ -954,12 +934,8 @@ static void __msc_set_storage_scan_cur_path(char *scan_path)
 {
        g_mutex_lock(&storage_scan_mutex2);
 
-       if (NULL == scan_path) {
-               MS_SAFE_FREE(g_storage_scan_path);
-       } else {
-               MS_SAFE_FREE(g_storage_scan_path);
-               g_storage_scan_path = strdup(scan_path);
-       }
+       g_free(g_storage_scan_path);
+       g_storage_scan_path = g_strdup(scan_path);
 
        g_mutex_unlock(&storage_scan_mutex2);
 }
@@ -982,12 +958,12 @@ static int __msc_dir_and_storage_scan_same_path(char *start_path)
        if (remain_path != NULL)
                remain_len = strlen(remain_path);
 
-       storage_path = strndup(start_path, strlen(start_path) - remain_len);
+       storage_path = g_strndup(start_path, strlen(start_path) - remain_len);
 
        g_mutex_lock(&dir_scan_mutex2);
 
        if (NULL == g_dir_scan_path || NULL == storage_path) {
-               MS_SAFE_FREE(storage_path);
+               g_free(storage_path);
                g_mutex_unlock(&dir_scan_mutex2);
 
                return MS_MEDIA_ERR_INTERNAL;
@@ -1001,7 +977,7 @@ static int __msc_dir_and_storage_scan_same_path(char *start_path)
        else
                ret = strncmp(storage_path, g_dir_scan_path, storage_len);
 
-       MS_SAFE_FREE(storage_path);
+       g_free(storage_path);
        g_mutex_unlock(&dir_scan_mutex2);
 
        return abs(ret);
@@ -1012,12 +988,8 @@ static void __msc_set_dir_scan_cur_path(char *scan_path)
 {
        g_mutex_lock(&dir_scan_mutex2);
 
-       if (NULL == scan_path) {
-               MS_SAFE_FREE(g_dir_scan_path);
-       } else {
-               MS_SAFE_FREE(g_dir_scan_path);
-               g_dir_scan_path = strdup(scan_path);
-       }
+       g_free(g_dir_scan_path);
+       g_dir_scan_path = g_strdup(scan_path);
 
        g_mutex_unlock(&dir_scan_mutex2);
 }
@@ -1115,12 +1087,7 @@ gboolean msc_directory_scan_thread(void *data)
                        goto NEXT;
                }
 
-               storage_id = strdup(scan_data->storage_id);
-               if (storage_id == NULL) {
-                       MS_DBG_ERR("storage_id NULL");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
+               storage_id = g_strdup(scan_data->storage_id);
 
                MS_DBG("path [%.*s], storage_id [%s], scan_type [%d]", MAX_MSG_SIZE, scan_data->msg, storage_id, scan_type);
 
@@ -1311,9 +1278,9 @@ NEXT:
                scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
                msc_send_result(ret, scan_data);
 
-               MS_SAFE_FREE(scan_data);
-               MS_SAFE_FREE(storage_id);
-               MS_SAFE_FREE(folder_uuid);
+               g_free(scan_data);
+               g_free(storage_id);
+               g_free(folder_uuid);
 
                g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
                __msc_del_cur_scan_item();
@@ -1329,7 +1296,7 @@ NEXT:
        }                       /*thread while*/
 
 _POWEROFF:
-       MS_SAFE_FREE(scan_data);
+       g_free(scan_data);
        if (handle) ms_disconnect_db(handle);
 
        return false;
@@ -1409,11 +1376,6 @@ gboolean msc_storage_scan_thread(void *data)
                }
 
                update_path = g_strdup(scan_data->msg);
-               if (!MS_STRING_VALID(update_path)) {
-                       MS_DBG_ERR("Invalid update_path");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
 
                ret = __msc_check_memory_status(uid);
                if (ret != MS_MEDIA_ERR_NONE) {
@@ -1475,7 +1437,7 @@ gboolean msc_storage_scan_thread(void *data)
 NEXT:
                __msc_del_blocked_path();
 
-               MS_SAFE_FREE(update_path);
+               g_free(update_path);
 
                if (power_off2) {
                        MS_DBG_ERR("power off");
@@ -1491,7 +1453,7 @@ NEXT:
                scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
                msc_send_result(ret, scan_data);
 
-               MS_SAFE_FREE(scan_data);
+               g_free(scan_data);
 
                MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
 
@@ -1500,7 +1462,7 @@ NEXT:
        }                       /*thread while*/
 
 _POWEROFF:
-       MS_SAFE_FREE(scan_data);
+       g_free(scan_data);
        if (handle) ms_disconnect_db(handle);
 
        return false;
@@ -1524,7 +1486,7 @@ static void __msc_clear_file_list(GArray *path_array)
                        char *data = NULL;
                        data = g_array_index(path_array , char*, 0);
                        g_array_remove_index(path_array, 0);
-                       MS_SAFE_FREE(data);
+                       g_free(data);
                }
                g_array_free(path_array, FALSE);
                path_array = NULL;
@@ -1551,30 +1513,21 @@ static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
        memset(buf, 0x0, MS_FILE_PATH_LEN_MAX);
        /* This is an array for storing the path of insert datas*/
        *path_array = g_array_new(FALSE, FALSE, sizeof(char *));
-       if (*path_array == NULL) {
-               MS_DBG_ERR("g_array_new failed");
-               res = MS_MEDIA_ERR_OUT_OF_MEMORY;
-               goto FREE_RESOURCE;
-       }
 
        /* read registering file path from stored file */
        while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
                length = strlen(buf); /*the return value of function, strlen(), includes "\n" */
-               path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
+               path = g_strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
 
                /* check valid path */
                ret = ms_check_ignore_dir(path, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_SERR("invalide path : %s", path);
-                       MS_SAFE_FREE(path);
+                       g_free(path);
                        continue;
                }
                /* insert getted path to the list */
-               if (g_array_append_val(*path_array, path) == NULL) {
-                       MS_DBG_ERR("g_array_append_val failed");
-                       res = MS_MEDIA_ERR_OUT_OF_MEMORY;
-                       goto FREE_RESOURCE;
-               }
+               g_array_append_val(*path_array, path);
        }
 
        if (fp) fclose(fp);
@@ -1725,10 +1678,6 @@ gboolean msc_register_thread(void *data)
                }
 
                file_path = g_strdup(register_data->msg);
-               if (file_path == NULL) {
-                       MS_DBG_ERR("file_path is NULL");
-                       goto FREE_RESOURCE;
-               }
 
                ret = __msc_make_file_list(file_path, &path_array, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
@@ -1749,19 +1698,19 @@ FREE_RESOURCE:
 
                __msc_clear_file_list(path_array);
 
-               MS_SAFE_FREE(file_path);
-               MS_SAFE_FREE(register_data);
+               g_free(file_path);
+               g_free(register_data);
                usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
 _POWEROFF:
-       MS_SAFE_FREE(file_path);
-       MS_SAFE_FREE(register_data);
+       g_free(file_path);
+       g_free(register_data);
        if (register_array) {
                while (register_array->len != 0) {
                        msg_data = g_array_index(register_array , ms_comm_msg_s*, 0);
                        g_array_remove_index(register_array, 0);
-                       MS_SAFE_FREE(msg_data);
+                       g_free(msg_data);
                }
                g_array_free(register_array, FALSE);
                register_array = NULL;
@@ -1775,31 +1724,27 @@ _POWEROFF:
 static int __msc_set_scan_item(s_scan_item** item, const char* path, int pid)
 {
        s_scan_item* scan_item = *item;
-       if (scan_item != NULL) {
-               MS_SAFE_FREE(scan_item->path);
-               scan_item->pid = -1;
-       } else {
-               scan_item = (s_scan_item*)malloc(sizeof(s_scan_item));
-               if (scan_item == NULL) {
-                       MS_DBG_ERR("malloc item failed...");
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-               memset(scan_item, 0, sizeof(s_scan_item));
-       }
 
-       scan_item->path = strdup(path);
+       if (!scan_item)
+               scan_item = g_new0(s_scan_item, 1);
+
+       g_free(scan_item->path);
+
+       scan_item->path = g_strdup(path);
        scan_item->pid = pid;
+
        *item = scan_item;
 
        MS_DBG_SWARN("path[%s],pid[%d]", scan_item->path, scan_item->pid);
+
        return MS_MEDIA_ERR_NONE;
 }
 
 static void __msc_del_scan_item(s_scan_item** item)
 {
        if (*item != NULL) {
-               MS_SAFE_FREE((*item)->path);
-               MS_SAFE_FREE(*item);
+               g_free((*item)->path);
+               g_free(*item);
        }
 }
 
@@ -1858,10 +1803,10 @@ void msc_set_blocked_path(const char *blocked_path)
 
        if (g_blocked_path2 != NULL) {
                MS_DBG_SWARN("g_blocked_path is not NULL [%s]", g_blocked_path2);
-               MS_SAFE_FREE(g_blocked_path2);
+               g_free(g_blocked_path2);
        }
 
-       g_blocked_path2 = strdup(blocked_path);
+       g_blocked_path2 = g_strdup(blocked_path);
 
        g_mutex_unlock(&blocked_mutex2);
 
@@ -1977,13 +1922,13 @@ int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
 
        switch (scan_type) {
        case MS_SCAN_STORAGE:
-               g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(storage_queue2, recv_msg);
                break;
        case MS_SCAN_DIRECTORY:
-               g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(scan_queue2, recv_msg);
                break;
        case MS_SCAN_REGISTER:
-               g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(reg_queue2, recv_msg);
                break;
        default:
                MS_DBG_ERR("invalid parameter");
@@ -2002,35 +1947,26 @@ void msc_stop_scan_thread(void)
 
        if (scan_queue2) {
                /*notify to scannig thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_DIRECTORY, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_DIRECTORY, data);
        }
 
        if (reg_queue2) {
                /*notify to register thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_REGISTER, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_REGISTER, data);
        }
 
        if (storage_queue2) {
                /*notify to register thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_STORAGE, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_STORAGE, data);
        }
 }
 
index 749a814..ab9d893 100755 (executable)
@@ -74,9 +74,9 @@ static void __msc_remove_request(GAsyncQueue *req_queue, ms_comm_msg_s *recv_msg
                        if ((strcmp(msg->msg, cancel_path) == 0) && (pid == msg->pid)) {
                                msg->msg_type = MS_MSG_DIRECTORY_SCANNING_CANCEL;
                                msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
-                               MS_SAFE_FREE(msg);
+                               g_free(msg);
                        } else {
-                               g_async_queue_push(temp_scan_queue, GINT_TO_POINTER(msg));
+                               g_async_queue_push(temp_scan_queue, msg);
                        }
                }
 
@@ -85,7 +85,7 @@ static void __msc_remove_request(GAsyncQueue *req_queue, ms_comm_msg_s *recv_msg
                for (; j < len; j++) {
                        msg = g_async_queue_pop(temp_scan_queue);
                        if (msg)
-                               g_async_queue_push(scan_queue2, GINT_TO_POINTER(msg));
+                               g_async_queue_push(scan_queue2, msg);
                }
                g_async_queue_unref(temp_scan_queue);
                MS_DBG_WARN("end update scan_queue2");
@@ -110,9 +110,9 @@ END_REMOVE_REQUEST:
                                                msg->msg_type = MS_MSG_DIRECTORY_SCANNING_CANCEL;
                                                msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
                                        }
-                                       MS_SAFE_FREE(msg);
+                                       g_free(msg);
                                } else {
-                                       g_async_queue_push(temp_extract_queue, GINT_TO_POINTER(msg));
+                                       g_async_queue_push(temp_extract_queue, msg);
                                }
                        }
 
@@ -121,7 +121,7 @@ END_REMOVE_REQUEST:
                        for (; j < len; j++) {
                                msg = g_async_queue_pop(temp_extract_queue);
                                if (msg)
-                                       g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(msg));
+                                       g_async_queue_push(folder_extract_queue, msg);
                        }
                        g_async_queue_unref(temp_extract_queue);
                        MS_DBG_WARN("end update folder_extract_queue");
@@ -142,33 +142,29 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
        sockfd = g_io_channel_unix_get_fd(src);
        if (sockfd < 0) {
                MS_DBG_ERR("sock fd is invalid!");
-               return TRUE;
+               return G_SOURCE_CONTINUE;
        }
 
-       MS_MALLOC(recv_msg, sizeof(ms_comm_msg_s));
-       if (recv_msg == NULL) {
-               MS_DBG_ERR("MS_MALLOC failed");
-               return TRUE;
-       }
+       recv_msg = g_new0(ms_comm_msg_s, 1);
 
        /* read() is blocked until media scanner sends message */
        err = read(sockfd, recv_msg, sizeof(ms_comm_msg_s));
        if (err < 0) {
                MS_DBG_STRERROR("fifo read failed");
-               MS_SAFE_FREE(recv_msg);
-               return MS_MEDIA_ERR_INTERNAL;
+               g_free(recv_msg);
+               return G_SOURCE_CONTINUE;
        }
 
        if (strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE) {
                MS_DBG_ERR("msg size is invlid");
-               MS_SAFE_FREE(recv_msg);
-               return TRUE;
+               g_free(recv_msg);
+               return G_SOURCE_CONTINUE;
        }
 
        if (strlen(recv_msg->storage_id) >= MS_UUID_SIZE) {
                MS_DBG_ERR("storage_id size is invlid");
-               MS_SAFE_FREE(recv_msg);
-               return TRUE;
+               g_free(recv_msg);
+               return G_SOURCE_CONTINUE;
        }
 
        MS_DBG_SLOG("receive msg from [%d][%d] M[%.*s] S[%.*s]", recv_msg->pid, recv_msg->msg_type, MAX_MSG_SIZE, recv_msg->msg, MS_UUID_SIZE, recv_msg->storage_id);
@@ -181,7 +177,7 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
                {
                        MS_DBG_INFO("BULK INSERT");
                        /* request bulk insert*/
-                       g_async_queue_push(reg_queue2, GINT_TO_POINTER(recv_msg));
+                       g_async_queue_push(reg_queue2, recv_msg);
                }
                break;
        case MS_MSG_DIRECTORY_SCANNING:
@@ -189,7 +185,7 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
                {
                        /* this request from another apps */
                        /* set the scan data for scanning thread */
-                       g_async_queue_push(scan_queue2, GINT_TO_POINTER(recv_msg));
+                       g_async_queue_push(scan_queue2, recv_msg);
                }
                break;
        case MS_MSG_STORAGE_ALL:
@@ -197,20 +193,20 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
        case MS_MSG_STORAGE_INVALID:
                {
                        /* this request from media-server */
-                       g_async_queue_push(storage_queue2, GINT_TO_POINTER(recv_msg));
+                       g_async_queue_push(storage_queue2, recv_msg);
                }
                break;
        case MS_MSG_DIRECTORY_SCANNING_CANCEL:
                {
                        __msc_remove_request(scan_queue2, recv_msg);
                        msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, recv_msg);
-                       MS_SAFE_FREE(recv_msg);
+                       g_free(recv_msg);
                }
                break;
        default:
                {
                        MS_DBG_ERR("THIS REQUEST IS INVALID %d", req_num);
-                       MS_SAFE_FREE(recv_msg);
+                       g_free(recv_msg);
                }
                break;
        }
@@ -218,7 +214,7 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
        /*Active flush */
        malloc_trim(0);
 
-       return TRUE;
+       return G_SOURCE_CONTINUE;
 }
 
 int msc_send_ready(void)
index a48a1f6..2c888ce 100644 (file)
@@ -60,8 +60,8 @@ static void __msc_remove_event_receiver(void);
 
 static void _power_off_cb(void* data)
 {
-       ms_comm_msg_s *scan_data;
-       ms_comm_msg_s *reg_data;
+       ms_comm_msg_s *scan_data = NULL;
+       ms_comm_msg_s *reg_data = NULL;
 
        MS_DBG_ERR("POWER OFF CB Begin");
 
@@ -71,47 +71,42 @@ static void _power_off_cb(void* data)
 
        if (scan_queue2) {
                /*notify to scannig thread*/
-               MS_MALLOC(scan_data, sizeof(ms_comm_msg_s));
-               if (scan_data != NULL) {
-                       scan_data->pid = POWEROFF;
-                       g_async_queue_push(scan_queue2, GINT_TO_POINTER(scan_data));
-               }
+               scan_data = g_new0(ms_comm_msg_s, 1);
+
+               scan_data->pid = POWEROFF;
+               g_async_queue_push(scan_queue2, scan_data);
        }
 
        if (reg_queue2) {
                /*notify to register thread*/
-               MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
-               if (reg_data != NULL) {
-                       reg_data->pid = POWEROFF;
-                       g_async_queue_push(reg_queue2, GINT_TO_POINTER(reg_data));
-               }
+               reg_data = g_new0(ms_comm_msg_s, 1);
+
+               reg_data->pid = POWEROFF;
+               g_async_queue_push(reg_queue2, reg_data);
        }
 
        if (storage_queue2) {
                /*notify to register thread*/
-               MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
-               if (reg_data != NULL) {
-                       reg_data->pid = POWEROFF;
-                       g_async_queue_push(storage_queue2, GINT_TO_POINTER(reg_data));
-               }
+               reg_data = g_new0(ms_comm_msg_s, 1);
+
+               reg_data->pid = POWEROFF;
+               g_async_queue_push(storage_queue2, reg_data);
        }
 
        if (storage_extract_queue) {
                /*notify to storage extract thread*/
-               MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
-               if (reg_data != NULL) {
-                       reg_data->pid = POWEROFF;
-                       g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(reg_data));
-               }
+               reg_data = g_new0(ms_comm_msg_s, 1);
+
+               reg_data->pid = POWEROFF;
+               g_async_queue_push(storage_extract_queue, reg_data);
        }
 
        if (folder_extract_queue) {
                /*notify to folder extract thread*/
-               MS_MALLOC(reg_data, sizeof(ms_comm_msg_s));
-               if (reg_data != NULL) {
-                       reg_data->pid = POWEROFF;
-                       g_async_queue_push(folder_extract_queue, GINT_TO_POINTER(reg_data));
-               }
+               reg_data = g_new0(ms_comm_msg_s, 1);
+
+               reg_data->pid = POWEROFF;
+               g_async_queue_push(folder_extract_queue, reg_data);
        }
 
        if (g_main_loop_is_running(scanner_mainloop2)) g_main_loop_quit(scanner_mainloop2);
@@ -191,7 +186,7 @@ static void __msc_datadisc_vconf_cb(void *data)
        }
 
 END:
-       MS_SAFE_FREE(disc_type);
+       g_free(disc_type);
 }
 #endif
 
index bf0c1c1..4b069c2 100644 (file)
@@ -170,7 +170,7 @@ static int __msc_db_update(sqlite3 *handle, const char *storage_id, const ms_com
 
                ms_set_folder_validity(handle, storage_id, start_path, 0, true, scan_data->uid);
 
-               MS_SAFE_FREE(start_path);
+               g_free(start_path);
        }
 
        sync();
@@ -225,7 +225,7 @@ static int __msc_directory_scan_update_and_delete(sqlite3 *handle, ms_comm_msg_s
        ret = ms_get_folder_id(handle, scan_data->storage_id, scan_data->msg, &folder_uuid);
        if (ret != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("ms_get_folder_id failed");
-               MS_SAFE_FREE(start_path);
+               g_free(start_path);
                return ret;
        }
 
@@ -244,7 +244,7 @@ static int __msc_directory_scan_update_and_delete(sqlite3 *handle, ms_comm_msg_s
                ret = ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
        }
 
-       MS_SAFE_FREE(folder_uuid);
+       g_free(folder_uuid);
 
        return ret;
 }
@@ -308,12 +308,12 @@ NEXT:
                malloc_trim(0);
 
                msc_send_result(ret, scan_data);
-               MS_SAFE_FREE(scan_data);
+               g_free(scan_data);
                MS_DBG_INFO("DIRECTORY SCAN END [%d]", ret);
        }                       /*thread while*/
 
 _POWEROFF:
-       MS_SAFE_FREE(scan_data);
+       g_free(scan_data);
 
        return false;
 }
@@ -422,12 +422,12 @@ NEXT:
                malloc_trim(0);
 
                msc_send_result(ret, scan_data);
-               MS_SAFE_FREE(scan_data);
+               g_free(scan_data);
 
                MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
        }                       /*thread while*/
 _POWEROFF:
-       MS_SAFE_FREE(scan_data);
+       g_free(scan_data);
 
        return FALSE;
 }
@@ -449,13 +449,13 @@ static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t u
        while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
                /* Remove '\n' */
                length = strlen(buf);
-               path = strndup(buf, length - 1);
+               path = g_strndup(buf, length - 1);
 
                /* check valid path */
                ret = ms_check_ignore_dir(path, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_SERR("invalide path : %s", path);
-                       MS_SAFE_FREE(path);
+                       g_free(path);
                        continue;
                }
 
@@ -540,12 +540,12 @@ NEXT:
                malloc_trim(0);
 
                msc_send_result(ret, register_data);
-               MS_SAFE_FREE(register_data);
+               g_free(register_data);
                MS_DBG_WARN("BULK REGISTER END [%d]", ret);
        }                       /*thread while*/
 
 _POWEROFF:
-       MS_SAFE_FREE(register_data);
+       g_free(register_data);
 
        return false;
 }
@@ -565,7 +565,7 @@ gboolean msc_metadata_update(void *data)
        ms_disconnect_db(handle);
 
        msc_send_result(ret, scan_data);
-       MS_SAFE_FREE(scan_data);
+       g_free(scan_data);
 
        MS_DBG_INFO("META UPDATE END [%d]", ret);
 
@@ -608,13 +608,13 @@ int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
 
        switch (scan_type) {
        case MS_SCAN_STORAGE:
-               g_async_queue_push(storage_queue, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(storage_queue, recv_msg);
                break;
        case MS_SCAN_DIRECTORY:
-               g_async_queue_push(scan_queue, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(scan_queue, recv_msg);
                break;
        case MS_SCAN_REGISTER:
-               g_async_queue_push(reg_queue, GINT_TO_POINTER(recv_msg));
+               g_async_queue_push(reg_queue, recv_msg);
                break;
        default:
                MS_DBG_ERR("invalid parameter");
@@ -633,35 +633,26 @@ void msc_send_power_off_request(void)
 
        if (scan_queue) {
                /*notify to scannig thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_DIRECTORY, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_DIRECTORY, data);
        }
 
        if (reg_queue) {
                /*notify to register thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_REGISTER, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_REGISTER, data);
        }
 
        if (storage_queue) {
                /*notify to register thread*/
-               MS_MALLOC(data, sizeof(ms_comm_msg_s));
-               if (data != NULL) {
-                       data->pid = POWEROFF;
-                       msc_push_scan_request(MS_SCAN_STORAGE, data);
-               } else {
-                       MS_DBG_ERR("memory allocation failed");
-               }
+               data = g_new0(ms_comm_msg_s, 1);
+
+               data->pid = POWEROFF;
+               msc_push_scan_request(MS_SCAN_STORAGE, data);
        }
 }
 
@@ -687,9 +678,9 @@ void msc_remove_dir_scan_request(ms_comm_msg_s *recv_msg)
                msg = g_async_queue_pop(scan_queue);
                if ((g_strcmp0(msg->msg, recv_msg->msg) == 0) && (recv_msg->pid == msg->pid)) {
                        MS_DBG("Find request. Remove it");
-                       MS_SAFE_FREE(msg);
+                       g_free(msg);
                } else {
-                       g_async_queue_push(temp_scan_queue, GINT_TO_POINTER(msg));
+                       g_async_queue_push(temp_scan_queue, msg);
                }
        }
        g_async_queue_unref(scan_queue);
index 1af79ed..b13fb8c 100755 (executable)
@@ -42,26 +42,25 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
        sockfd = g_io_channel_unix_get_fd(src);
        MS_DBG_RETVM_IF(sockfd < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
 
-       MS_MALLOC(recv_msg, sizeof(ms_comm_msg_s));
-       MS_DBG_RETVM_IF(!recv_msg, G_SOURCE_CONTINUE, "MS_MALLOC failed");
+       recv_msg = g_new0(ms_comm_msg_s, 1);
 
        /* read() is blocked until media scanner sends message */
        err = read(sockfd, recv_msg, sizeof(ms_comm_msg_s));
        if (err < 0) {
                MS_DBG_STRERROR("fifo read failed");
-               MS_SAFE_FREE(recv_msg);
+               g_free(recv_msg);
                return G_SOURCE_CONTINUE;
        }
 
        if (strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE) {
                MS_DBG_ERR("msg size is invlid");
-               MS_SAFE_FREE(recv_msg);
+               g_free(recv_msg);
                return G_SOURCE_CONTINUE;
        }
 
        if (strlen(recv_msg->storage_id) >= MS_UUID_SIZE) {
                MS_DBG_ERR("storage_id size is invlid");
-               MS_SAFE_FREE(recv_msg);
+               g_free(recv_msg);
                return G_SOURCE_CONTINUE;
        }
 
@@ -82,14 +81,14 @@ gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer d
                break;
        case MS_MSG_DIRECTORY_SCANNING_CANCEL:
                msc_remove_dir_scan_request(recv_msg);
-               MS_SAFE_FREE(recv_msg);
+               g_free(recv_msg);
                break;
        case MS_MSG_STORAGE_META:
                msc_metadata_update_thread(recv_msg);
                break;
        default:
                MS_DBG_ERR("THIS REQUEST IS INVALID %d", recv_msg->msg_type);
-               MS_SAFE_FREE(recv_msg);
+               g_free(recv_msg);
                break;
        }
 
index 3d53d0d..b27b47b 100755 (executable)
@@ -65,7 +65,7 @@ int ms_reset_mediadb(uid_t uid)
        if (error)
                g_error_free(error);
 
-       MS_SAFE_FREE(db_path);
+       g_free(db_path);
 
        MS_DBG_ERR("[MEDIA DB RESET END]");
 
index 3ce447e..4ff3051 100755 (executable)
@@ -82,25 +82,22 @@ static gboolean __ms_dcm_agent_prepare_tcp_socket(int *sock_fd, unsigned short s
 static int __ms_dcm_recv_msg(int sock, dcmMsg *msg)
 {
        int recv_msg_len = 0;
-       unsigned char *buf = NULL;
-
-       MS_MALLOC(buf, sizeof(dcmMsg));
-       MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+       unsigned char *buf = g_malloc0(sizeof(dcmMsg));
 
        if ((recv_msg_len = recv(sock, buf, sizeof(dcmMsg), 0)) < 0) {
                MS_DBG_STRERROR("recv failed");
-               MS_SAFE_FREE(buf);
+               g_free(buf);
                return MS_MEDIA_ERR_IPC;
        }
        memcpy(msg, buf, sizeof(dcmMsg));
 
        if (strlen(msg->msg) >= MAX_FILEPATH_LEN) {
                MS_DBG_ERR("msg size is invlid[%zu]", strlen(msg->msg));
-               MS_SAFE_FREE(buf);
+               g_free(buf);
                return MS_MEDIA_ERR_IPC;
        }
 
-       MS_SAFE_FREE(buf);
+       g_free(buf);
 
        MS_DBG("msg_type [%d]", msg->msg_type);
 
@@ -313,8 +310,8 @@ static gboolean __ms_dcm_request_to_server(gpointer data)
 
        if (client_sock <= 0 || !recv_msg) {
                MS_DBG_ERR("client sock is below 0 or recv msg is NULL");
-               MS_SAFE_FREE(req->recv_msg);
-               MS_SAFE_FREE(req);
+               g_free(req->recv_msg);
+               g_free(req);
                return G_SOURCE_CONTINUE;
        }
 
@@ -336,8 +333,8 @@ static gboolean __ms_dcm_request_to_server(gpointer data)
 
                close(client_sock);
 
-               MS_SAFE_FREE(req->recv_msg);
-               MS_SAFE_FREE(req);
+               g_free(req->recv_msg);
+               g_free(req);
 
                return G_SOURCE_CONTINUE;
        }
@@ -348,8 +345,8 @@ static gboolean __ms_dcm_request_to_server(gpointer data)
                MS_DBG_STRERROR("sendto failed");
 
        close(client_sock);
-       MS_SAFE_FREE(req->recv_msg);
-       MS_SAFE_FREE(req);
+       g_free(req->recv_msg);
+       g_free(req);
 
        return G_SOURCE_CONTINUE;
 }
@@ -359,6 +356,7 @@ static gboolean __ms_dcm_agent_read_socket(GIOChannel *src, GIOCondition conditi
        struct sockaddr_un client_addr;
        unsigned int client_addr_len;
        dcmMsg *recv_msg = NULL;
+       dcmRequest *dcm_req = NULL;
        int sock = -1;
        int client_sock = -1;
 
@@ -374,24 +372,14 @@ static gboolean __ms_dcm_agent_read_socket(GIOChannel *src, GIOCondition conditi
 
        MS_DBG("Client[%d] is accepted", client_sock);
 
-       recv_msg = calloc(1, sizeof(dcmMsg));
-       if (!recv_msg) {
-               MS_DBG_ERR("Failed to allocate memodry");
-               goto ERROR;
-       }
+       recv_msg = g_new0(dcmMsg, 1);
 
        if (__ms_dcm_recv_msg(client_sock, recv_msg) < 0) {
                MS_DBG_ERR("__ms_dcm_recv_msg failed ");
                goto ERROR;
        }
 
-       dcmRequest *dcm_req = NULL;
-
-       MS_MALLOC(dcm_req, sizeof(dcmRequest));
-       if (!dcm_req) {
-               MS_DBG_ERR("Failed to create request element");
-               goto ERROR;
-       }
+       dcm_req = g_new0(dcmRequest, 1);
 
        dcm_req->client_sock = client_sock;
        dcm_req->recv_msg = recv_msg;
@@ -416,8 +404,8 @@ static gboolean __ms_dcm_agent_read_socket(GIOChannel *src, GIOCondition conditi
                        MS_DBG("Sent Refuse msg from %.*s", MAX_FILEPATH_LEN, recv_msg->msg);
 
                close(client_sock);
-               MS_SAFE_FREE(dcm_req->recv_msg);
-               MS_SAFE_FREE(dcm_req);
+               g_free(dcm_req->recv_msg);
+               g_free(dcm_req);
 
                return G_SOURCE_CONTINUE;
        }
@@ -437,7 +425,7 @@ static gboolean __ms_dcm_agent_read_socket(GIOChannel *src, GIOCondition conditi
 
 ERROR:
        close(client_sock);
-       MS_SAFE_FREE(recv_msg);
+       g_free(recv_msg);
        return G_SOURCE_CONTINUE;
 }
 
index 498116d..5763975 100644 (file)
@@ -45,7 +45,7 @@ int ms_storage_insert_handler(const char *mount_path, const char *mount_uuid)
 
        if (mount_path != NULL && mount_uuid != NULL) {
                /*CHECK DB HERE */
-               uuid = strndup(mount_uuid, strlen(mount_uuid));
+               uuid = g_strndup(mount_uuid, strlen(mount_uuid));
                ret = ms_check_db_upgrade(handle, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_check_db_upgrade failed");
@@ -92,8 +92,8 @@ int ms_storage_insert_handler(const char *mount_path, const char *mount_uuid)
        }
 
 ERROR:
-       MS_SAFE_FREE(storage_path);
-       MS_SAFE_FREE(uuid);
+       g_free(storage_path);
+       g_free(uuid);
 
        ms_disconnect_db(handle);
 
@@ -193,8 +193,8 @@ static void __ms_usb_add_event(const char *mount_path)
        }
 
 ERROR:
-       MS_SAFE_FREE(storage_id);
-       MS_SAFE_FREE(storage_path);
+       g_free(storage_id);
+       g_free(storage_path);
 
        ms_disconnect_db(handle);
 }
@@ -306,7 +306,7 @@ static int __ms_check_mounted_storage_list(GArray **added_list)
                                                mount_path = usb_device_get_mountpath(device);
                                                if (mount_path != NULL) {
                                                        MS_DBG_SWARN("mount_path [%s]", mount_path);
-                                                       storage_path = strdup(mount_path);
+                                                       storage_path = g_strdup(mount_path);
                                                        g_array_append_val(*added_list, storage_path);
                                                }
                                        } else {
@@ -317,7 +317,7 @@ static int __ms_check_mounted_storage_list(GArray **added_list)
                                                mount_path = usb_device_get_mountpath(device);
                                                if (mount_path != NULL) {
                                                        MS_DBG_SWARN("mount_path [%s]", mount_path);
-                                                       storage_path = strdup(mount_path);
+                                                       storage_path = g_strdup(mount_path);
                                                        g_array_append_val(*added_list, storage_path);
                                                }
                                        } else {
@@ -374,7 +374,7 @@ int ms_check_mounted_storage(uid_t uid)
                                ret = ms_insert_storage(handle, device_uuid, mounted_path, uid);
 
                                scan_type = MS_SCAN_ALL;
-                               storage_id = strdup(device_uuid);
+                               storage_id = g_strdup(device_uuid);
 
                                MS_SAFE_FREE(device_uuid);
                        } else {
@@ -386,7 +386,7 @@ int ms_check_mounted_storage(uid_t uid)
                                if (ret == 0) {
                                        if (validity == 1) {
                                                MS_DBG_ERR("This storage is already updated.");
-                                               MS_SAFE_FREE(db_storage_path);
+                                               g_free(db_storage_path);
                                                continue;
                                        }
 
@@ -406,7 +406,7 @@ int ms_check_mounted_storage(uid_t uid)
                                                ms_set_folder_scan_status(handle, storage_id, NULL, MS_DIR_SCAN_NONE, uid);
 
                                                scan_type = MS_SCAN_PART;
-                                               MS_SAFE_FREE(db_storage_path);
+                                               g_free(db_storage_path);
                                        } else {
                                                /* there is no information of this storage in Media DB */
                                                MS_DBG_SWARN("insert storage %s", mounted_path);
@@ -430,12 +430,12 @@ int ms_check_mounted_storage(uid_t uid)
                                MS_DBG_ERR("error : ms_insert_folder failed");
 
                        ms_send_storage_otg_scan_request(mounted_path, storage_id, scan_type, uid);
-                       MS_SAFE_FREE(storage_id);
+                       g_free(storage_id);
                }
 
                for (i = 0; i < count; i++) {
                        mounted_path = g_array_index(added_list, char*, 0);
-                       MS_SAFE_FREE(mounted_path);
+                       g_free(mounted_path);
                        g_array_remove_index(added_list, 0);
                }
 
index 84aedaa..876650c 100644 (file)
@@ -226,8 +226,8 @@ static void __ms_datadisc_vconf_cb(void *data)
        }
 
 END:
-       MS_SAFE_FREE(disc_type);
-       MS_SAFE_FREE(disc_path);
+       g_free(disc_type);
+       g_free(disc_path);
        g_free(storage_path);
 }
 #endif
@@ -379,12 +379,12 @@ static void __ms_change_lang_vconf_cb(keynode_t *key, void* data)
                MS_DBG_WARN("language is changed but do not update meta data");
        }
 
-       MS_SAFE_FREE(priv_lang);
+       g_free(priv_lang);
 
        if (MS_STRING_VALID(lang))
-               priv_lang = strdup(lang);
+               priv_lang = g_strdup(lang);
 
-       MS_SAFE_FREE(lang);
+       g_free(lang);
 }
 #endif
 
@@ -538,14 +538,14 @@ static void __ms_add_event_receiver(GIOChannel *channel)
        if (MS_STRING_VALID(lang)) {
                MS_DBG("Set language change cb [%s]", lang);
 
-               priv_lang = strdup(lang);
+               priv_lang = g_strdup(lang);
 
                err = vconf_notify_key_changed(VCONFKEY_LANGSET, (vconf_callback_fn) __ms_change_lang_vconf_cb, NULL);
                if (err == -1)
                        MS_DBG_ERR("add call back function for event %s fails", VCONFKEY_LANGSET);
        }
 
-       MS_SAFE_FREE(lang);
+       g_free(lang);
 
 #endif
 #ifdef _USE_SENIOR_MODE
@@ -693,9 +693,9 @@ static int __ms_check_disc_status(void)
        }
 
 END:
-       MS_SAFE_FREE(disc_type);
-       MS_SAFE_FREE(disc_path);
-       MS_SAFE_FREE(storage_path);
+       g_free(disc_type);
+       g_free(disc_path);
+       g_free(storage_path);
 
        return MS_MEDIA_ERR_NONE;
 }
index 5a7bcc6..e75a43a 100644 (file)
@@ -53,8 +53,8 @@ static void __destroy_owner_data(gpointer data)
        ms_req_owner_data **_data = (ms_req_owner_data **) data;
 
        close((*_data)->client_sockfd);
-       MS_SAFE_FREE((*_data)->req_path);
-       MS_SAFE_FREE(*_data);
+       g_free((*_data)->req_path);
+       g_free(*_data);
        MS_DBG("DELETE OWNER");
 }
 
@@ -69,13 +69,11 @@ static int __ms_add_owner(int pid, int client_sock, char *path)
 
        if (!owner_list) {
                owner_list = g_array_new(FALSE, FALSE, sizeof(ms_req_owner_data *));
-               MS_DBG_RETVM_IF(!owner_list, MS_MEDIA_ERR_OUT_OF_MEMORY, "g_array_new failed");
                g_array_set_clear_func(owner_list, __destroy_owner_data);
        }
 
        /* store pid and client address */
-       MS_MALLOC(owner_data, sizeof(ms_req_owner_data));
-       MS_DBG_RETVM_IF(!owner_data, MS_MEDIA_ERR_OUT_OF_MEMORY, "MS_MALLOC failed");
+       owner_data = g_new0(ms_req_owner_data, 1);
 
        owner_data->pid = pid;
        owner_data->client_sockfd = client_sock;
@@ -334,7 +332,7 @@ int ms_send_scan_request(ms_comm_msg_s *send_msg, int client_sock)
 
 int ms_send_storage_scan_request(const char *root_path, const char *storage_id, ms_dir_scan_type_t scan_type, uid_t uid)
 {
-       ms_comm_msg_s scan_msg = { 0, };
+       ms_comm_msg_s scan_msg = {0, };
        MS_DBG_RETVM_IF(uid == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid UID");
 
        memset(&scan_msg, 0, sizeof(scan_msg));
@@ -379,8 +377,8 @@ int ms_send_storage_scan_request_senior_mode(sqlite3 *handle)
        int validity = 0;
        ms_dir_scan_type_t scan_type = MS_SCAN_ALL;
        char *storage_path = NULL;
-       char* storage_id = strdup("familytv");
-       char* path = MEDIA_ROOT_PATH_SENIOR_MODE;
+       const char* storage_id = g_strdup("familytv");
+       const char* path = MEDIA_ROOT_PATH_SENIOR_MODE;
 
        ms_sys_get_uid(&uid);
 
@@ -404,7 +402,7 @@ int ms_send_storage_scan_request_senior_mode(sqlite3 *handle)
                        }
 
                        scan_type = MS_SCAN_PART;
-                       MS_SAFE_FREE(storage_path);
+                       g_free(storage_path);
                } else {
                        /* there is no information of this storage in Media DB */
                        MS_DBG_SWARN("##[senior mode]insert storage %s", path);
@@ -426,7 +424,7 @@ int ms_send_storage_scan_request_senior_mode(sqlite3 *handle)
                MS_DBG_ERR("##[senior mode]error : ms_insert_folder failed");
 
        ms_send_storage_otg_scan_request(path, storage_id, scan_type, uid);
-       MS_SAFE_FREE(storage_id);
+       g_free(storage_id);
 
        return ret;
 }
index dc9abb0..37c52e2 100755 (executable)
@@ -91,13 +91,12 @@ static int __ms_thumb_recv_msg(int sock, thumbMsg *msg)
        unsigned char *buf = NULL;
        unsigned int header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
 
-       MS_MALLOC(buf, header_size);
-       MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+       buf = g_malloc0(header_size);
 
        while (header_size > 0) {
                if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
                        MS_DBG_STRERROR("recv failed");
-                       MS_SAFE_FREE(buf);
+                       g_free(buf);
                        return MS_MEDIA_ERR_IPC;
                }
                header_size -= recv_len;
@@ -108,7 +107,7 @@ static int __ms_thumb_recv_msg(int sock, thumbMsg *msg)
        recv_pos = 0;
 
        memcpy(msg, buf, header_size);
-       MS_SAFE_FREE(buf);
+       g_free(buf);
 
        MS_DBG("status[%d]", msg->status);
 
@@ -119,13 +118,13 @@ static int __ms_thumb_recv_msg(int sock, thumbMsg *msg)
        MS_DBG_RETV_IF(msg->thumb_size == 0, MS_MEDIA_ERR_NONE);
 
        remain_size = msg->thumb_size;
-       MS_MALLOC(buf, remain_size);
-       MS_DBG_RETV_IF(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
+
+       buf = g_malloc0(remain_size);
 
        while (remain_size > 0) {
                if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
                        MS_DBG_STRERROR("recv failed");
-                       MS_SAFE_FREE(buf);
+                       g_free(buf);
                        return MS_MEDIA_ERR_IPC;
                }
                fsync(sock);
@@ -134,17 +133,11 @@ static int __ms_thumb_recv_msg(int sock, thumbMsg *msg)
                remain_size -= recv_len;
        }
 
-       MS_SAFE_FREE(msg->thumb_data);
+       g_free(msg->thumb_data);
 
-       MS_MALLOC(msg->thumb_data, (unsigned int)(msg->thumb_size));
-       if (msg->thumb_data) {
-               memcpy(msg->thumb_data, buf, msg->thumb_size);
-       } else {
-               MS_SAFE_FREE(buf);
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
+       msg->thumb_data = g_memdup(buf, msg->thumb_size);
 
-       MS_SAFE_FREE(buf);
+       g_free(buf);
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -159,10 +152,11 @@ static int __ms_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *bu
        MS_DBG_SLOG("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data[%d]", header_size, req_msg->org_path, req_msg->dst_path, req_msg->thumb_size);
 
        size = header_size + req_msg->thumb_size;
-       MS_MALLOC(*buf, size);
-       MS_DBG_RETV_IF(!(*buf), MS_MEDIA_ERR_OUT_OF_MEMORY);
+
+       *buf = g_malloc0(size);
 
        memcpy(*buf, req_msg, header_size);
+
        if (req_msg->thumb_size > 0)
                memcpy((*buf) + header_size, req_msg->thumb_data, req_msg->thumb_size);
 
@@ -255,12 +249,12 @@ static gboolean __ms_thumb_agent_send_msg_to_thumb_server(thumbMsg *recv_msg, th
 
        if (send(sock, buf, buf_size, 0) < 0) {
                MS_DBG_STRERROR("send failed");
-               MS_SAFE_FREE(buf);
+               g_free(buf);
                close(sock);
                return FALSE;
        }
 
-       MS_SAFE_FREE(buf);
+       g_free(buf);
        MS_DBG_SLOG("Sending msg to thumbnail server is successful");
 
        if (recv_msg->msg_type == THUMB_REQUEST_KILL_SERVER) {
@@ -363,8 +357,8 @@ static gboolean __ms_thumb_request_to_server(gpointer data)
 
        if (client_sock <= 0 || !recv_msg) {
                MS_DBG_ERR("client sock is below 0 or recv msg is NULL");
-               MS_SAFE_FREE(req->recv_msg);
-               MS_SAFE_FREE(req);
+               g_free(req->recv_msg);
+               g_free(req);
                return G_SOURCE_CONTINUE;
        }
 
@@ -392,9 +386,9 @@ static gboolean __ms_thumb_request_to_server(gpointer data)
 
                close(client_sock);
 
-               MS_SAFE_FREE(buf);
-               MS_SAFE_FREE(req->recv_msg);
-               MS_SAFE_FREE(req);
+               g_free(buf);
+               g_free(req->recv_msg);
+               g_free(req);
 
                return G_SOURCE_CONTINUE;
        }
@@ -418,9 +412,9 @@ static gboolean __ms_thumb_request_to_server(gpointer data)
        }
 
        close(client_sock);
-       MS_SAFE_FREE(buf);
-       MS_SAFE_FREE(req->recv_msg);
-       MS_SAFE_FREE(req);
+       g_free(buf);
+       g_free(req->recv_msg);
+       g_free(req);
        MS_SAFE_FREE(res_msg.thumb_data);
 
        return G_SOURCE_CONTINUE;
@@ -448,23 +442,14 @@ static gboolean __ms_thumb_agent_read_socket(GIOChannel *src, GIOCondition condi
 
        MS_DBG("Client[%d] is accepted", client_sock);
 
-       recv_msg = calloc(1, sizeof(thumbMsg));
-       if (!recv_msg) {
-               MS_DBG_ERR("Failed to allocate memory");
-               close(client_sock);
-               return G_SOURCE_CONTINUE;
-       }
+       recv_msg = g_new0(thumbMsg, 1);
 
        if (__ms_thumb_recv_msg(client_sock, recv_msg) < 0) {
                MS_DBG_ERR("_ms_thumb_recv_msg failed ");
                goto ERROR;
        }
 
-       MS_MALLOC(thumb_req, sizeof(thumbRequest));
-       if (!thumb_req) {
-               MS_DBG_ERR("Failed to create request element");
-               goto ERROR;
-       }
+       thumb_req = g_new0(thumbRequest, 1);
 
        thumb_req->client_sock = client_sock;
        thumb_req->recv_msg = recv_msg;
@@ -493,7 +478,7 @@ static gboolean __ms_thumb_agent_read_socket(GIOChannel *src, GIOCondition condi
                else
                        MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);
 
-               MS_SAFE_FREE(buf);
+               g_free(buf);
                goto ERROR;
        }
 
@@ -511,9 +496,9 @@ static gboolean __ms_thumb_agent_read_socket(GIOChannel *src, GIOCondition condi
        return G_SOURCE_CONTINUE;
 ERROR:
        close(client_sock);
-       MS_SAFE_FREE(recv_msg->thumb_data);
-       MS_SAFE_FREE(recv_msg);
-       MS_SAFE_FREE(thumb_req);
+       g_free(recv_msg->thumb_data);
+       g_free(recv_msg);
+       g_free(thumb_req);
        return G_SOURCE_CONTINUE;
 }