Skip to content

Commit 3532523

Browse files
committed
Add more checks in zip_close
1 parent fa391e9 commit 3532523

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/lib/otezip.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,15 @@ int zip_close(zip_t *za) {
12731273
return -1;
12741274
}
12751275
/* Finalize archive if in write mode */
1276+
int finalize_ret = 0;
12761277
if (za->mode == 1) {
1277-
otezip_finalize_archive (za);
1278+
finalize_ret = otezip_finalize_archive (za);
12781279
}
12791280

12801281
if (za->fp) {
1281-
fclose (za->fp);
1282+
if (fclose (za->fp) != 0 && finalize_ret == 0) {
1283+
finalize_ret = -1;
1284+
}
12821285
}
12831286
zip_uint64_t i;
12841287
for (i = 0; i < za->n_entries; i++) {
@@ -1288,7 +1291,7 @@ int zip_close(zip_t *za) {
12881291
}
12891292
free (za->entries);
12901293
free (za);
1291-
return 0;
1294+
return finalize_ret;
12921295
}
12931296

12941297
zip_uint64_t zip_get_num_files(zip_t *za) {

0 commit comments

Comments
 (0)