diff --git a/mz_zip_rw.c b/mz_zip_rw.c index d6d19e3c..be6bc74e 100644 --- a/mz_zip_rw.c +++ b/mz_zip_rw.c @@ -845,21 +845,19 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir) { resolved_name_size += (int)strlen(destination_dir) + 1; } - if (!path) { - path = (char *)malloc(resolved_name_size); - utf8_name = (char *)malloc(utf8_name_size); - resolved_name = (char *)malloc(resolved_name_size); - } else { - path = (char *)realloc(path, resolved_name_size); - utf8_name = (char *)realloc(utf8_name, utf8_name_size); - resolved_name = (char *)realloc(resolved_name, resolved_name_size); - } + char *new_path = (char *)realloc(path, resolved_name_size); + char *new_utf8_name = (char *)realloc(utf8_name, utf8_name_size); + char *new_resolved_name = (char *)realloc(resolved_name, resolved_name_size); - if (!path || !utf8_name || !resolved_name) { + if (!new_path || !new_utf8_name || !new_resolved_name) { err = MZ_MEM_ERROR; goto save_all_cleanup; } + path = new_path; + utf8_name = new_utf8_name; + resolved_name = new_resolved_name; + /* Construct output path */ path[0] = 0;