coverity fix 70/201470/3
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 14 Mar 2019 10:29:07 +0000 (19:29 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Fri, 15 Mar 2019 01:48:18 +0000 (10:48 +0900)
Change-Id: I20c613f763a46473d0ed3eb4f12bf8d6cc014e98
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
src/tzip/tzip-utility.c

index 4a2ca5f..a958023 100644 (file)
@@ -155,17 +155,16 @@ static void fileinfo_to_stat(unz_file_info *file_info, struct stat *file_stat, m
 static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path,
                unz_file_info *file_info, mode_t mode)
 {
-       char *dir;
-       char *cpy_path;
-       char *next_dir;
-       char *parent_dir;
-       char *save_ptr;
+       char *dir = NULL;
+       char *cpy_path = NULL;
+       char *next_dir = NULL;
+       char *parent_dir = NULL;
+       char *save_ptr = NULL;
        int ret = 0;
 
        if (!strchr(path, '/')) {
                /* file or directory in root directory */
-               ret = add_dir_info(entry, ".", path, file_info, mode);
-               return ret;
+               return add_dir_info(entry, ".", path, file_info, mode);
        }
        /* add info about each directory in path */
        parent_dir = malloc(strlen(path) + 1);
@@ -177,16 +176,27 @@ static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path,
        /* needed copy, because of strtok_r modify cstring */
        cpy_path = strndup(path, strlen(path) + 1);
        if (!cpy_path) {
-               free(parent_dir);
                _E("Failed to malloc.");
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err;
        }
 
        dir = strtok_r(cpy_path, "/", &save_ptr);
+       if (dir == NULL) {
+               _E("Failed to strtok_r.");
+               ret = -EINVAL;
+               goto err;
+       }
        ret = add_dir_info(entry, ".", dir, file_info, S_IFDIR);
 
        strncpy(parent_dir, dir, strlen(dir) + 1);
        dir = strtok_r(NULL, "/", &save_ptr);
+       if (dir == NULL) {
+               _E("Failed to strtok_r.");
+               ret = -EINVAL;
+               goto err;
+       }
+
        next_dir = strtok_r(NULL, "/", &save_ptr);
 
        while (next_dir && !ret) {
@@ -197,13 +207,9 @@ static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path,
                next_dir = strtok_r(NULL, "/", &save_ptr);
        }
 
-       if (ret) {
-               free(cpy_path);
-               free(parent_dir);
-               return ret;
-       }
-
-       ret = add_dir_info(entry, parent_dir, dir, file_info, mode);
+       if (!ret)
+               ret = add_dir_info(entry, parent_dir, dir, file_info, mode);
+err:
        free(cpy_path);
        free(parent_dir);