Skip to content

Commit 785497c

Browse files
committed
Fix leaks in Phar::webPhar()
1 parent c9bc7dd commit 785497c

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

ext/phar/phar_object.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -681,39 +681,30 @@ PHP_METHOD(Phar, webPhar)
681681
if (FAILURE == zend_fcall_info_init(rewrite, 0, &fci, &fcc, NULL, NULL)) {
682682
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: invalid rewrite callback");
683683

684+
cleanup_fail:
685+
zval_ptr_dtor(&params);
684686
if (free_pathinfo) {
685687
efree(path_info);
686688
}
689+
efree(entry);
687690
efree(pt);
688-
689691
RETURN_THROWS();
690692
}
691693

692694
fci.param_count = 1;
693695
fci.params = &params;
694-
Z_ADDREF(params);
695696
fci.retval = &retval;
696697

697698
if (FAILURE == zend_call_function(&fci, &fcc)) {
698699
if (!EG(exception)) {
699700
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: failed to call rewrite callback");
700701
}
701-
702-
if (free_pathinfo) {
703-
efree(path_info);
704-
}
705-
efree(pt);
706-
707-
RETURN_THROWS();
702+
goto cleanup_fail;
708703
}
709704

710705
if (Z_TYPE_P(fci.retval) == IS_UNDEF || Z_TYPE(retval) == IS_UNDEF) {
711-
if (free_pathinfo) {
712-
efree(path_info);
713-
}
714706
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false");
715-
efree(pt);
716-
RETURN_THROWS();
707+
goto cleanup_fail;
717708
}
718709

719710
switch (Z_TYPE(retval)) {
@@ -734,13 +725,8 @@ PHP_METHOD(Phar, webPhar)
734725
zend_bailout();
735726
return;
736727
default:
737-
if (free_pathinfo) {
738-
efree(path_info);
739-
}
740-
efree(pt);
741-
742728
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false");
743-
RETURN_THROWS();
729+
goto cleanup_fail;
744730
}
745731
}
746732

0 commit comments

Comments
 (0)