common: fix memory leak issues 98/114498/2
authortaeyoung <ty317.kim@samsung.com>
Mon, 13 Feb 2017 12:35:01 +0000 (21:35 +0900)
committertaeyoung <ty317.kim@samsung.com>
Tue, 14 Feb 2017 02:32:14 +0000 (11:32 +0900)
Change-Id: I956e59695285e2ef9285008360c4393677dd54be
Signed-off-by: taeyoung <ty317.kim@samsung.com>
src/block/block.c
src/tzip/tzip-utility.c

index 716ea08..ee287e8 100644 (file)
@@ -1935,6 +1935,12 @@ static int add_operation(struct block_device *bdev,
                        get_operation_char(operation, name, sizeof(name)),
                        bdev->data->devnode);
 
+       thread_id = bdev->thread_id;
+       if (thread_id < 0 || thread_id >= THREAD_MAX) {
+               _E("Fail to find thread to add");
+               return -EPERM;
+       }
+
        op = (struct operation_queue *)malloc(sizeof(struct operation_queue));
        if (!op) {
                _E("malloc failed");
@@ -1948,12 +1954,6 @@ static int add_operation(struct block_device *bdev,
                msg = dbus_message_ref(msg);
        op->msg = msg;
 
-       thread_id = bdev->thread_id;
-       if (thread_id < 0 || thread_id >= THREAD_MAX) {
-               _E("Fail to find thread to add");
-               return -EPERM;
-       }
-
        /* LOCK
         * during adding queue and checking the queue length */
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
@@ -2101,6 +2101,8 @@ static int add_block_device(struct udev_device *dev, const char *devnode)
        thread_id = find_thread(bdev->data->devnode);
        if (thread_id < 0 || thread_id >= THREAD_MAX) {
                _E("Fail to find thread to add");
+               free_block_data(data);
+               free(bdev);
                return -EPERM;
        }
        bdev->thread_id = thread_id;
index 3553788..100c975 100644 (file)
@@ -226,7 +226,7 @@ int add_dir_info(struct tzip_mount_entry *entry, const char *parent_dir,
                        return -ENOMEM;
                }
 
-               dinfo->file_hash =  g_hash_table_new_full(
+               dinfo->file_hash = g_hash_table_new_full(
                                g_str_hash, g_str_equal, NULL, NULL);
                if (!dinfo->file_hash) {
                        _E("Malloc failed");
@@ -238,6 +238,7 @@ int add_dir_info(struct tzip_mount_entry *entry, const char *parent_dir,
                dinfo->name = (char *)malloc(len);
                if (!dinfo->name) {
                        _E("Malloc failed");
+                       g_hash_table_unref(dinfo->file_hash);
                        free(dinfo);
                        return -ENOMEM;
                }