Skip to content

Commit ebb590b

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix bug #76524 - ZipArchive memory leak
2 parents 474292c + 08f0885 commit ebb590b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ext/zip/php_zip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,10 +1026,13 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
10261026
}
10271027
if (intern->za) {
10281028
if (zip_close(intern->za) != 0) {
1029+
#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1
1030+
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", "zip_close have failed");
1031+
#else
10291032
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za));
1030-
return;
1033+
zip_discard(intern->za);
1034+
#endif
10311035
}
1032-
intern->za = NULL;
10331036
}
10341037

10351038
if (intern->buffers_cnt>0) {

ext/zip/tests/bug76524.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
ZipArchive Bug #76524 (memory leak with ZipArchive::OVERWRITE flag and empty archive)
3+
--SKIPIF--
4+
<?php
5+
if(!extension_loaded('zip')) die('skip');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
$filename = __DIR__ . '/nonexistent.zip';
11+
12+
$zip = new ZipArchive();
13+
$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
14+
echo 'ok';
15+
16+
/* Zip-related error messages depend on platform and libzip version,
17+
so the regex is used to check that Zend MM does NOT show warnings
18+
about leaks: */
19+
?>
20+
--EXPECTREGEX--
21+
ok((?!memory leaks detected).)*

0 commit comments

Comments
 (0)