1
0
mirror of https://github.com/php/php-src.git synced 2026-04-20 14:31:06 +02:00
Files
archived-php-src/ext/random/tests/03_randomizer/construct_twice.phpt
Go Kudo 34b352d121 Fix memory leak on Randomizer::__construct() call twice (#9091)
When Radomizer::__construct() was called with no arguments, Randomizer\Engine\Secure was implicitly instantiate and memory was leaking.
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
2022-07-24 03:09:14 +09:00

41 lines
892 B
PHP

--TEST--
Random: Randomizer: Disallow manually calling __construct
--FILE--
<?php
final class UserEngine implements \Random\Engine
{
public function generate(): string
{
return \random_byte(4); /* 32-bit */
}
}
try {
(new \Random\Randomizer())->__construct();
} catch (\BadMethodCallException $e) {
echo $e->getMessage() . PHP_EOL;
}
try {
$r = new \Random\Randomizer(new \Random\Engine\Xoshiro256StarStar());
$r->__construct(new \Random\Engine\PcgOneseq128XslRr64());
} catch (\BadMethodCallException $e) {
echo $e->getMessage() . PHP_EOL;
}
try {
$r = new \Random\Randomizer(new \UserEngine());
$r->__construct(new \UserEngine());
} catch (\BadMethodCallException $e) {
echo $e->getMessage() . PHP_EOL;
}
die('success');
?>
--EXPECT--
Cannot call constructor twice
Cannot call constructor twice
Cannot call constructor twice
success