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);
/* 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) {
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);