AmendHub

Download:

jcs

/

subtext

/

amendments

/

406

zip: Use xmalloc/xfree, it's no longer fatal


jcs made amendment 406 about 1 year ago
--- zip.c Tue Mar 7 22:55:34 2023 +++ zip.c Mon Mar 13 22:51:24 2023 @@ -195,8 +195,7 @@ zip_read_file(Str255 path, zip_extract_decider *decide goto read_fail; if (decider(filename, uncomp_len)) { - /* don't use xmalloc, these are not fatal */ - comp = malloc(comp_len); + comp = xmalloc(comp_len); if (comp == NULL) { logger_printf("[zip] failed to malloc(%ld) for " "compressed data", comp_len); @@ -205,29 +204,29 @@ zip_read_file(Str255 path, zip_extract_decider *decide /* read compressed data */ if (zip_read(frefnum, comp, comp_len) != comp_len) { - free(comp); + xfree(&comp); goto read_fail; } - uncomp = malloc(uncomp_len); + uncomp = xmalloc(uncomp_len); if (uncomp == NULL) { logger_printf("[zip] failed to malloc(%ld) for " "uncompressed data", uncomp_len); - free(comp); + xfree(&comp); goto read_fail; } ret = puff(uncomp, &uncomp_len, comp, &comp_len); if (ret != 0) { logger_printf("[zip] unzip failed: %d", ret); - free(comp); - free(uncomp); + xfree(&comp); + xfree(&uncomp); goto read_fail; } - free(comp); + xfree(&comp); processor(filename, uncomp, uncomp_len); - free(uncomp); + xfree(&uncomp); } else { /* skip over it */ SetFPos(frefnum, fsFromMark, comp_len);