Skip to content

Commit cd34fc9

Browse files
committed
Fix memory leak of doc blocks of static properties
When declaring the same static property with a doc block in a class and in a trait, the doc block of the property in the class is leaked. This fixes #12207.
1 parent 0b614a6 commit cd34fc9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Overriding a static property where both declarations have a doc block does not leak memory
3+
--FILE--
4+
<?php
5+
trait MyTrait {
6+
/**
7+
* trait comment
8+
*/
9+
static $property;
10+
}
11+
12+
class MyClass {
13+
use MyTrait;
14+
15+
/**
16+
* class comment
17+
*/
18+
static $property;
19+
}
20+
--EXPECT--

Zend/zend_API.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,6 +4332,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43324332
(property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
43334333
property_info->offset = property_info_ptr->offset;
43344334
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
4335+
if (property_info_ptr->doc_comment) {
4336+
zend_string_release(property_info_ptr->doc_comment);
4337+
}
43354338
zend_hash_del(&ce->properties_info, name);
43364339
} else {
43374340
property_info->offset = ce->default_static_members_count++;
@@ -4350,6 +4353,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43504353
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
43514354
property_info->offset = property_info_ptr->offset;
43524355
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
4356+
if (property_info_ptr->doc_comment) {
4357+
zend_string_release_ex(property_info_ptr->doc_comment, 1);
4358+
}
43534359
zend_hash_del(&ce->properties_info, name);
43544360

43554361
ZEND_ASSERT(ce->type == ZEND_INTERNAL_CLASS);

0 commit comments

Comments
 (0)