Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@ static void zend_do_traits_constant_binding(zend_class_entry *ce, zend_class_ent
constant->ce = ce;

Z_TRY_ADDREF(constant->value);
zend_type_copy_ctor(&constant->type, /* use_arena */ true, /* persistent */ false);
constant->doc_comment = constant->doc_comment ? zend_string_copy(constant->doc_comment) : NULL;
if (constant->attributes && (!(GC_FLAGS(constant->attributes) & IS_ARRAY_IMMUTABLE))) {
GC_ADDREF(constant->attributes);
Expand Down Expand Up @@ -3489,6 +3490,7 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
Z_PTR(p->val) = new_c;
memcpy(new_c, c, sizeof(zend_class_constant));
new_c->ce = ce;
zend_type_copy_ctor(&new_c->type, /* use_arena */ true, /* persistent */ false);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ ZEND_API void destroy_zend_class(zval *zv)
zend_hash_release(c->attributes);
}
}
if (c->ce == ce) {
zend_type_release(c->type, /* persistent */ 0);
}
} ZEND_HASH_FOREACH_END();
}
zend_hash_destroy(&ce->constants_table);
Expand Down
29 changes: 29 additions & 0 deletions ext/opcache/tests/gh25149.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-25149 (Memory leak of class constant type names in classes not cached by opcache)
--EXTENSIONS--
opcache
--INI--
opcache.enable_cli=1
--FILE--
<?php

eval('class A { const ?GH25149_B C = null; }');
eval('class D { const GH25149_E|GH25149_F|null G = null; }');
var_dump(A::C, D::G);

eval('trait T { const ?GH25149_H I = null; const GH25149_J|GH25149_K|null L = null; }');
eval('class M { use T; }');
var_dump(M::I, M::L);

eval('class N {}');
class O extends N { const ?GH25149_P Q = null; const GH25149_R|GH25149_S|null U = null; }
var_dump(O::Q, O::U);

?>
--EXPECT--
NULL
NULL
NULL
NULL
NULL
NULL
Loading