summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2018-07-10 11:20:50 +0200
committerAnatol Belski <ab@php.net>2018-07-10 11:20:50 +0200
commitd82cb24e197d0b7b6ad0837c385ecbfd93fcffbd (patch)
treea15e83b3aadd10429c1057352eb3cf026f341829
parent7da042cbd8381ba9e21caeec4f1d0fe08c289e44 (diff)
parentebb590b625efb443e43bad8b0cfd915bc20c380e (diff)
downloadphp-git-d82cb24e197d0b7b6ad0837c385ecbfd93fcffbd.tar.gz
Merge branch 'PHP-7.2'
* PHP-7.2: Fix bug #76524 - ZipArchive memory leak
-rw-r--r--ext/zip/php_zip.c7
-rw-r--r--ext/zip/tests/bug76524.phpt21
2 files changed, 26 insertions, 2 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index 319c1ddc66..4fedabad1c 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1029,10 +1029,13 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
}
if (intern->za) {
if (zip_close(intern->za) != 0) {
+#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
+ php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", "zip_close have failed");
+#else
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za));
- return;
+ zip_discard(intern->za);
+#endif
}
- intern->za = NULL;
}
if (intern->buffers_cnt>0) {
diff --git a/ext/zip/tests/bug76524.phpt b/ext/zip/tests/bug76524.phpt
new file mode 100644
index 0000000000..f28bfc13f2
--- /dev/null
+++ b/ext/zip/tests/bug76524.phpt
@@ -0,0 +1,21 @@
+--TEST--
+ZipArchive Bug #76524 (memory leak with ZipArchive::OVERWRITE flag and empty archive)
+--SKIPIF--
+<?php
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+
+$filename = __DIR__ . '/nonexistent.zip';
+
+$zip = new ZipArchive();
+$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
+echo 'ok';
+
+/* Zip-related error messages depend on platform and libzip version,
+ so the regex is used to check that Zend MM does NOT show warnings
+ about leaks: */
+?>
+--EXPECTREGEX--
+ok((?!memory leaks detected).)*