-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--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 |