Skip to content

Commit 910f579

Browse files
rioderelftedevnexen
authored andcommittedSep 18, 2023
Fix GH-12207 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. While at it, possibly fix doc comment for internal classes. Close GH-12238
1 parent 486276f commit 910f579

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.25
44

5+
- Core:
6+
. Fixed bug GH-12207 (memory leak when class using trait with doc block).
7+
(rioderelfte)
8+
59
- Filter:
610
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)
711

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
?>
21+
--EXPECT--

‎Zend/zend_API.c

+6
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
41204120
(property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
41214121
property_info->offset = property_info_ptr->offset;
41224122
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
4123+
if (property_info_ptr->doc_comment) {
4124+
zend_string_release(property_info_ptr->doc_comment);
4125+
}
41234126
zend_hash_del(&ce->properties_info, name);
41244127
} else {
41254128
property_info->offset = ce->default_static_members_count++;
@@ -4142,6 +4145,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
41424145
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
41434146
property_info->offset = property_info_ptr->offset;
41444147
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
4148+
if (property_info_ptr->doc_comment) {
4149+
zend_string_release_ex(property_info_ptr->doc_comment, 1);
4150+
}
41454151
zend_hash_del(&ce->properties_info, name);
41464152

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

0 commit comments

Comments
 (0)
Please sign in to comment.