]> granicus.if.org Git - php/commitdiff
Fix leak when setting dynamic property on generator
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 16 Oct 2020 14:57:50 +0000 (16:57 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 16 Oct 2020 14:58:27 +0000 (16:58 +0200)
Zend/tests/generators/dynamic_properties.phpt
Zend/zend_object_handlers.c

index d42eed914abb03c17a7ee940e7948880cbfd6828..08ceb7f581c69f58b7f8bf6d946280c0b61c68cd 100644 (file)
@@ -9,7 +9,7 @@ function gen() {
 
 $gen = gen();
 try {
-    $gen->prop = 42;
+    $gen->prop = new stdClass;
 } catch (Error $e) {
     echo $e->getMessage(), "\n";
 }
index ecf5c71ed8dd1a41846829c8acc00b53e922a760..f091d679f681b98af8fa368e4553db10a4320eaf 100644 (file)
@@ -772,11 +772,10 @@ found:
        } else {
                ZEND_ASSERT(!IS_WRONG_PROPERTY_OFFSET(property_offset));
 write_std_property:
-               Z_TRY_ADDREF_P(value);
                if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
-
                        variable_ptr = OBJ_PROP(zobj, property_offset);
 
+                       Z_TRY_ADDREF_P(value);
                        if (UNEXPECTED(prop_info)) {
                                ZVAL_COPY_VALUE(&tmp, value);
                                if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
@@ -794,6 +793,8 @@ write_std_property:
                                variable_ptr = &EG(error_zval);
                                goto exit;
                        }
+
+                       Z_TRY_ADDREF_P(value);
                        if (!zobj->properties) {
                                rebuild_object_properties(zobj);
                        }