Skip to content

Commit a4add68

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: phar: Fix memory leaks when creating temp file fails when applying zip signature
2 parents 1f809a5 + 33718fb commit a4add68

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/phar/zip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,9 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas
12221222
entry.fp_type = PHAR_MOD;
12231223
entry.is_modified = 1;
12241224
if (entry.fp == NULL) {
1225+
efree(signature);
12251226
spprintf(pass->error, 0, "phar error: unable to create temporary file for signature");
1227+
php_stream_close(newfile);
12261228
return FAILURE;
12271229
}
12281230

@@ -1440,11 +1442,12 @@ void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_def
14401442

14411443
phar_metadata_tracker_try_ensure_has_serialized_data(&phar->metadata_tracker, phar->is_persistent);
14421444
if (temperr) {
1445+
temperror:
14431446
if (error) {
14441447
spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", phar->fname, temperr);
14451448
}
14461449
efree(temperr);
1447-
temperror:
1450+
notemperror:
14481451
php_stream_close(pass.centralfp);
14491452
nocentralerror:
14501453
php_stream_close(pass.filefp);
@@ -1472,7 +1475,7 @@ void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_def
14721475
if (error) {
14731476
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);
14741477
}
1475-
goto temperror;
1478+
goto notemperror;
14761479
}
14771480
}
14781481

0 commit comments

Comments
 (0)