diff --git a/tools/funpack.c b/tools/funpack.c index ebaeda6..f17fc1b 100644 --- a/tools/funpack.c +++ b/tools/funpack.c @@ -126,19 +126,20 @@ static int extract_entry(const char *out_dir, const fpk_entry_t *entry, const void *data, size_t size) { char *full_path = join_path(out_dir, entry->path); - char *dir_part = dup_str(full_path); - char *slash = strrchr(dir_part, '/'); FILE *fp; - if (slash) { + if (strchr(entry->path, '/') != NULL) { + char *dir_part = dup_str(full_path); + char *slash = strrchr(dir_part, '/'); + *slash = '\0'; if (!mkdir_p(dir_part)) { free(dir_part); free(full_path); return 0; } + free(dir_part); } - free(dir_part); fp = fopen(full_path, "wb"); if (!fp) {