Commit 17f67529fd7 for php.net
commit 17f67529fd797da80176fbf5a591e89bf974434b
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date: Sat Jun 6 10:06:43 2026 +0200
zip: Fix leak when zip_fread() fails
Closes GH-22238.
diff --git a/NEWS b/NEWS
index e9014b130cd..e9226c59a0f 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,9 @@ PHP NEWS
(ndossche)
. Fixed memory leak in inflate_add(). (ndossche)
+- Zip:
+ . Fixed error-related memory leaks. (ndossche)
+
04 Jun 2026, PHP 8.4.22
- Date:
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index 2d0bf39845f..b29ba2c370b 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -2962,6 +2962,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
buffer = zend_string_safe_alloc(1, len, 0, 0);
zip_int64_t n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
if (n < 1) {
+ zip_fclose(zf);
zend_string_efree(buffer);
RETURN_EMPTY_STRING();
}