Skip to content

Commit

Permalink
Fix leaks in Phar::webPhar()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jun 25, 2020
1 parent c9bc7dd commit 785497c
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,39 +681,30 @@ PHP_METHOD(Phar, webPhar)
if (FAILURE == zend_fcall_info_init(rewrite, 0, &fci, &fcc, NULL, NULL)) {
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: invalid rewrite callback");

cleanup_fail:
zval_ptr_dtor(&params);
if (free_pathinfo) {
efree(path_info);
}
efree(entry);
efree(pt);

RETURN_THROWS();
}

fci.param_count = 1;
fci.params = &params;
Z_ADDREF(params);
fci.retval = &retval;

if (FAILURE == zend_call_function(&fci, &fcc)) {
if (!EG(exception)) {
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: failed to call rewrite callback");
}

if (free_pathinfo) {
efree(path_info);
}
efree(pt);

RETURN_THROWS();
goto cleanup_fail;
}

if (Z_TYPE_P(fci.retval) == IS_UNDEF || Z_TYPE(retval) == IS_UNDEF) {
if (free_pathinfo) {
efree(path_info);
}
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false");
efree(pt);
RETURN_THROWS();
goto cleanup_fail;
}

switch (Z_TYPE(retval)) {
Expand All @@ -734,13 +725,8 @@ PHP_METHOD(Phar, webPhar)
zend_bailout();
return;
default:
if (free_pathinfo) {
efree(path_info);
}
efree(pt);

zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false");
RETURN_THROWS();
goto cleanup_fail;
}
}

Expand Down

0 comments on commit 785497c

Please sign in to comment.