Skip to content

Commit 446210e

Browse files
committed
yomidbbuilder: fixes crash when attempting to add an invalid dictionary
libzip's zip_fclose() function does not no-op on NULL, so a check needs to be performed outside the function.
1 parent 8870190 commit 446210e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/dict/yomidbbuilder.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ static int get_json_obj(zip_t *archive, const char *filename, json_object **obj)
556556

557557
cleanup:
558558
free(contents);
559-
zip_fclose(file);
559+
if (file)
560+
{
561+
zip_fclose(file);
562+
}
560563

561564
return ret;
562565
}
@@ -1817,7 +1820,10 @@ static int extract_resources(zip_t *dict_archive, const char *res_dir)
18171820
{
18181821
fprintf(stderr, "Could not open file for writing\n%s\n", file_path);
18191822
free(file_path);
1820-
zip_fclose(zip_file);
1823+
if (zip_file)
1824+
{
1825+
zip_fclose(zip_file);
1826+
}
18211827
goto cleanup;
18221828
}
18231829
free(file_path);
@@ -1831,7 +1837,10 @@ static int extract_resources(zip_t *dict_archive, const char *res_dir)
18311837
fwrite(buf, sizeof(char), bytes_read, file);
18321838
}
18331839
fclose(file);
1834-
zip_fclose(zip_file);
1840+
if (zip_file)
1841+
{
1842+
zip_fclose(zip_file);
1843+
}
18351844
}
18361845

18371846
cleanup:

0 commit comments

Comments
 (0)