Skip to content

Commit

Permalink
Fix leak in isDefaultValueAvailable()
Browse files Browse the repository at this point in the history
Exposed in Symfony due to exit changes.
  • Loading branch information
nikic committed Jun 30, 2020
1 parent 8c11d8f commit c2b23d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2813,10 +2813,11 @@ ZEND_METHOD(ReflectionParameter, isDefaultValueConstant)
if (Z_TYPE(default_value) == IS_CONSTANT_AST) {
zend_ast *ast = Z_ASTVAL(default_value);
RETVAL_BOOL(ast->kind == ZEND_AST_CONSTANT || ast->kind == ZEND_AST_CONSTANT_CLASS);
zval_ptr_dtor_nogc(&default_value);
} else {
RETURN_FALSE;
RETVAL_FALSE;
}

zval_ptr_dtor_nogc(&default_value);
}
/* }}} */

Expand Down
22 changes: 22 additions & 0 deletions ext/reflection/tests/default_value_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Check that isDefaultValueConstant() does not leak
--FILE--
<?php

class Test {
public function method($param = [123]) {}
}

$rp = new ReflectionParameter(['Test', 'method'], 'param');
var_dump($rp->isDefaultValueAvailable());
var_dump($rp->isDefaultValueConstant());
var_dump($rp->getDefaultValue());

?>
--EXPECT--
bool(true)
bool(false)
array(1) {
[0]=>
int(123)
}

0 comments on commit c2b23d8

Please sign in to comment.