]> granicus.if.org Git - php/commitdiff
Fix leak on "Cannot assign by reference to overloaded object" error
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 08:07:54 +0000 (10:07 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 08:07:54 +0000 (10:07 +0200)
Zend/tests/bug70083.phpt
Zend/zend_execute.c

index 6b20eabb39612098d33c1f607d49b8d910adc822..5bc3656e9fca3ee735e90ae6a9a2a2b55f7da851 100644 (file)
@@ -13,12 +13,17 @@ class foo {
 function &noref() { $foo = 1; return $foo; }
 
 $foo = new foo;
-$foo->i = &noref();
+try {
+    $foo->i = &noref();
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
 var_dump($foo);
 
 ?>
---EXPECTF--
-Fatal error: Uncaught Error: Cannot assign by reference to overloaded object in %s:%d
-Stack trace:
-#0 {main}
-  thrown in %s on line %d
+--EXPECT--
+Cannot assign by reference to overloaded object
+object(foo)#1 (1) {
+  ["var":"foo":private]=>
+  NULL
+}
index 015ee8990ff9c4d4468f78572f8c60f63eb6a79e..b69d0a88d55e8623e0ad28e2155e61e59003a206 100644 (file)
@@ -2862,6 +2862,7 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
                variable_ptr = &EG(uninitialized_zval);
        } else if (UNEXPECTED(Z_TYPE(variable) != IS_INDIRECT)) {
                zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
+               zval_ptr_dtor(&variable);
                variable_ptr = &EG(uninitialized_zval);
        } else if (/*OP_DATA_TYPE == IS_VAR &&*/ UNEXPECTED(Z_ISERROR_P(value_ptr))) {
                variable_ptr = &EG(uninitialized_zval);