Skip to content

Commit 28e21d8

Browse files
committed
Fix leak when setting dynamic property on generator
1 parent 6669426 commit 28e21d8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Zend/tests/generators/dynamic_properties.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function gen() {
99

1010
$gen = gen();
1111
try {
12-
$gen->prop = 42;
12+
$gen->prop = new stdClass;
1313
} catch (Error $e) {
1414
echo $e->getMessage(), "\n";
1515
}

Zend/zend_object_handlers.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,10 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
772772
} else {
773773
ZEND_ASSERT(!IS_WRONG_PROPERTY_OFFSET(property_offset));
774774
write_std_property:
775-
Z_TRY_ADDREF_P(value);
776775
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
777-
778776
variable_ptr = OBJ_PROP(zobj, property_offset);
779777

778+
Z_TRY_ADDREF_P(value);
780779
if (UNEXPECTED(prop_info)) {
781780
ZVAL_COPY_VALUE(&tmp, value);
782781
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
@@ -794,6 +793,8 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
794793
variable_ptr = &EG(error_zval);
795794
goto exit;
796795
}
796+
797+
Z_TRY_ADDREF_P(value);
797798
if (!zobj->properties) {
798799
rebuild_object_properties(zobj);
799800
}

0 commit comments

Comments
 (0)