Fix crash issue 99/213299/3 accepted/tizen/unified/20190904.224442 submit/tizen/20190903.022206
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 4 Sep 2019 05:05:01 +0000 (14:05 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 4 Sep 2019 06:29:12 +0000 (15:29 +0900)
Change GArray to GPtrArray

Change-Id: I9bebfc08d370dcac9109fda2c39d639da7d3b817
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner/media-scanner-scan.c

index c4759f0..d6930b0 100755 (executable)
@@ -36,7 +36,7 @@ GAsyncQueue *scan_queue;
 GAsyncQueue *reg_queue;
 GMutex scan_req_mutex;
 
-static void __msc_clear_file_list(GArray *path_array);
+static void __msc_clear_file_list(GPtrArray *path_array);
 
 static bool __msc_is_stop_needed()
 {
@@ -54,18 +54,18 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
        GDir *dir = NULL;
        GError *error = NULL;
        const char *name;
-       GArray *dir_array = NULL;
+       GPtrArray *dir_array = NULL;
        char *current_path = NULL;
        char *path = NULL;
        int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL;
 
-       dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
+       dir_array = g_ptr_array_new();
        if (!dir_array) {
                MS_SAFE_FREE(start_path);
                return MS_MEDIA_ERR_OUT_OF_MEMORY;
        }
 
-       g_array_append_val(dir_array, start_path);
+       g_ptr_array_add(dir_array, start_path);
 
        scan_function = (check_exists == false) ? ms_insert_item_batch : ms_validate_item;
 
@@ -75,8 +75,8 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
                        goto STOP_SCAN;
                }
 
-               current_path = g_array_index(dir_array , char*, 0);
-               g_array_remove_index(dir_array, 0);
+               current_path = g_ptr_array_index(dir_array, 0);
+               g_ptr_array_remove_index(dir_array, 0);
 
                if (ms_check_scan_ignore(current_path, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
@@ -128,7 +128,7 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
                                MS_SAFE_FREE(path);
                        } else {
                                if (is_recursive) {
-                                       g_array_append_val(dir_array, path);
+                                       g_ptr_array_add(dir_array, path);
                                } else {
                                        ms_insert_folder(handle, storage_id, path, uid);
                                        MS_SAFE_FREE(path);
@@ -448,16 +448,15 @@ _POWEROFF:
        return FALSE;
 }
 
-static void __msc_clear_file_list(GArray *path_array)
+static void __msc_clear_file_list(GPtrArray *path_array)
 {
        if (!path_array)
                return;
 
-       g_array_set_clear_func(path_array, g_free);
-       g_array_free(path_array, TRUE);
+       g_ptr_array_free(path_array, TRUE);
 }
 
-static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
+static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
 {
        FILE *fp = NULL;
        char buf[MS_FILE_PATH_LEN_MAX] = {0,};
@@ -475,7 +474,7 @@ 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 *));
+       *path_array = g_ptr_array_new_with_free_func(g_free);
        if (*path_array == NULL) {
                MS_DBG_ERR("g_array_new failed");
                ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
@@ -495,11 +494,8 @@ static int __msc_make_file_list(char *file_path, GArray **path_array, uid_t uid)
                        continue;
                }
                /* insert getted path to the list */
-               if (g_array_append_val(*path_array, path) == NULL) {
-                       MS_DBG_ERR("g_array_append_val failed");
-                       ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
-                       goto FREE_RESOURCE;
-               }
+               g_ptr_array_add(*path_array, path);
+
        }
 
        if (fp) fclose(fp);
@@ -516,7 +512,7 @@ FREE_RESOURCE:
        return ret;
 }
 
-static int __msc_batch_insert(int pid, GArray *path_array, uid_t uid)
+static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
@@ -530,7 +526,7 @@ static int __msc_batch_insert(int pid, GArray *path_array, uid_t uid)
        ms_batch_commit_enable(true, false, true, pid);
 
        for (i = 0; i < path_array->len; i++) {
-               insert_path = g_array_index(path_array, char*, i);
+               insert_path = g_ptr_array_index(path_array, i);
 
                memset(storage_id, 0x0, MS_UUID_SIZE);
                if (ms_get_storage_id(handle, insert_path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
@@ -557,7 +553,7 @@ gboolean msc_register_thread(void *data)
 {
        int ret = MS_MEDIA_ERR_NONE;
        ms_comm_msg_s *register_data = NULL;
-       GArray *path_array = NULL;
+       GPtrArray *path_array = NULL;
 
        while (1) {
                register_data = g_async_queue_pop(reg_queue);