Skip to content

Commit 44a1ff5

Browse files
committed
Fix memory leak on failure in phar_convert_to_other()
1 parent 2f16221 commit 44a1ff5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ext/phar/phar_object.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,12 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert
22292229
PHAR_G(last_phar) = NULL;
22302230
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
22312231

2232+
php_stream *tmp_fp = php_stream_fopen_tmpfile();
2233+
if (tmp_fp == NULL) {
2234+
zend_throw_exception_ex(phar_ce_PharException, 0, "unable to create temporary file");
2235+
return NULL;
2236+
}
2237+
22322238
phar = (phar_archive_data *) ecalloc(1, sizeof(phar_archive_data));
22332239
/* set whole-archive compression and type from parameter */
22342240
phar->flags = flags;
@@ -2253,11 +2259,7 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert
22532259
zend_hash_init(&phar->virtual_dirs, sizeof(char *),
22542260
zend_get_hash_value, NULL, 0);
22552261

2256-
phar->fp = php_stream_fopen_tmpfile();
2257-
if (phar->fp == NULL) {
2258-
zend_throw_exception_ex(phar_ce_PharException, 0, "unable to create temporary file");
2259-
return NULL;
2260-
}
2262+
phar->fp = tmp_fp;
22612263
phar->fname = source->fname;
22622264
phar->fname_len = source->fname_len;
22632265
phar->is_temporary_alias = source->is_temporary_alias;

0 commit comments

Comments
 (0)