Skip to content

Commit c4333a7

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2 parents d05f88e + 913327d commit c4333a7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ext/phar/phar.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,18 +1682,19 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16821682
if (!PHAR_G(has_zlib)) {
16831683
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\" to temporary file, enable zlib extension in php.ini")
16841684
}
1685+
1686+
/* entire file is gzip-compressed, uncompress to temporary file */
1687+
if (!(temp = php_stream_fopen_tmpfile())) {
1688+
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1689+
}
1690+
16851691
array_init(&filterparams);
16861692
/* this is defined in zlib's zconf.h */
16871693
#ifndef MAX_WBITS
16881694
#define MAX_WBITS 15
16891695
#endif
16901696
add_assoc_long_ex(&filterparams, "window", sizeof("window") - 1, MAX_WBITS + 32);
16911697

1692-
/* entire file is gzip-compressed, uncompress to temporary file */
1693-
if (!(temp = php_stream_fopen_tmpfile())) {
1694-
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1695-
}
1696-
16971698
php_stream_rewind(fp);
16981699
filter = php_stream_filter_create("zlib.inflate", &filterparams, php_stream_is_persistent(fp));
16991700

0 commit comments

Comments
 (0)