Skip to content

Commit c54ea59

Browse files
committed
fix(zend): allocate erased list-typed bound on the compile arena to match its arena bit
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 7b4a15d commit c54ea59

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Generics: declaring a class with a DNF-typed bound does not leak memory
3+
--FILE--
4+
<?php
5+
interface A {}
6+
interface B {}
7+
interface C {}
8+
9+
class Holder<T: (A&B)|C> {
10+
public function take(T $x): void {}
11+
public function get(): T {}
12+
}
13+
14+
echo "ok\n";
15+
?>
16+
--EXPECT--
17+
ok
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Generics: declaring a class with an intersection-typed bound does not leak memory
3+
--FILE--
4+
<?php
5+
interface A {}
6+
interface B {}
7+
8+
class Holder<T: A&B> {
9+
public function take(T $x): void {}
10+
}
11+
12+
echo "ok\n";
13+
?>
14+
--EXPECT--
15+
ok
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Generics: declaring a class with a union-typed bound does not leak memory
3+
--FILE--
4+
<?php
5+
interface A {}
6+
interface B {}
7+
8+
class Holder<T: A|B> {
9+
public function take(T $x): void {}
10+
}
11+
12+
echo "ok\n";
13+
?>
14+
--EXPECT--
15+
ok

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5824,7 +5824,7 @@ static zend_result zend_compile_func_array_map(znode *result, zend_ast_list *arg
58245824
* breaking for the generated call.
58255825
*/
58265826
if (callback->kind == ZEND_AST_CALL
5827-
&& callback->child[0]->kind == ZEND_AST_ZVAL
5827+
&& callback->child[0]->kind == ZEND_AST_ZVAL
58285828
&& Z_TYPE_P(zend_ast_get_zval(callback->child[0])) == IS_STRING
58295829
&& zend_string_equals_literal_ci(zend_ast_get_str(callback->child[0]), "assert")) {
58305830
return FAILURE;
@@ -8090,7 +8090,7 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
80908090
} else if (ZEND_TYPE_HAS_LIST(result)) {
80918091
zend_type_list *orig_list = ZEND_TYPE_LIST(result);
80928092
size_t list_size = ZEND_TYPE_LIST_SIZE(orig_list->num_types);
8093-
zend_type_list *copy = emalloc(list_size);
8093+
zend_type_list *copy = zend_arena_alloc(&CG(arena), list_size);
80948094
memcpy(copy, orig_list, list_size);
80958095
for (uint32_t i = 0; i < copy->num_types; i++) {
80968096
if (ZEND_TYPE_HAS_NAME(copy->types[i])) {

0 commit comments

Comments
 (0)