Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
if (EG(exception)) {
PHP_JSON_HASH_UNPROTECT_RECURSION(recursion_rc);
zend_release_properties(prop_ht);
zval_ptr_dtor(&tmp);
return FAILURE;
}
}
Expand Down
44 changes: 44 additions & 0 deletions ext/json/tests/json_encode_hooked_property_throwing_getter.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
json_encode() releases the hooked property value when the get hook throws
--FILE--
<?php

class Value
{
public function __destruct()
{
echo "Value::__destruct\n";
}
}

class ThrowOnFree
{
public function __destruct()
{
throw new Exception('thrown while freeing the get hook frame');
}
}

class Container
{
public $hooked {
get {
$local = new ThrowOnFree();
return new Value();
}
}
}

try {
json_encode(new Container());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

echo "done\n";

?>
--EXPECT--
Value::__destruct
Exception: thrown while freeing the get hook frame
done
Loading