Skip to content

Commit

Permalink
Fix GH-12207 memory leak of doc blocks of static properties
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rioderelfte authored and devnexen committed Sep 18, 2023
1 parent 486276f commit 910f579
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.25

- Core:
. Fixed bug GH-12207 (memory leak when class using trait with doc block).
(rioderelfte)

- Filter:
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)

Expand Down
@@ -0,0 +1,21 @@
--TEST--
Overriding a static property where both declarations have a doc block does not leak memory
--FILE--
<?php
trait MyTrait {
/**
* trait comment
*/
static $property;
}

class MyClass {
use MyTrait;

/**
* class comment
*/
static $property;
}
?>
--EXPECT--
6 changes: 6 additions & 0 deletions Zend/zend_API.c
Expand Up @@ -4120,6 +4120,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
(property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
property_info->offset = property_info_ptr->offset;
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
if (property_info_ptr->doc_comment) {
zend_string_release(property_info_ptr->doc_comment);
}
zend_hash_del(&ce->properties_info, name);
} else {
property_info->offset = ce->default_static_members_count++;
Expand All @@ -4142,6 +4145,9 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
property_info->offset = property_info_ptr->offset;
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
if (property_info_ptr->doc_comment) {
zend_string_release_ex(property_info_ptr->doc_comment, 1);
}
zend_hash_del(&ce->properties_info, name);

ZEND_ASSERT(ce->type == ZEND_INTERNAL_CLASS);
Expand Down

0 comments on commit 910f579

Please sign in to comment.