-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix memory leak on Randomizer::__construct() call twice #9091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zeriyoshi
merged 12 commits into
php:master
from
zeriyoshi:randomizer_constructor_twice
Jul 23, 2022
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e9a447f
random: fix __construct() call twice
zeriyoshi 4adebfd
update NEWS
zeriyoshi a095e45
[CI skip] fix typo
zeriyoshi fc643aa
Merge branch 'master' into randomizer_constructor_twice
zeriyoshi 4afc9db
fix: replace all strlen -> sizeof - 1
zeriyoshi e9b9118
Update ext/random/tests/03_randomizer/construct_twice.phpt
zeriyoshi 8d38061
Revert "fix: replace all strlen -> sizeof - 1"
zeriyoshi 31b7f9a
random: revert strlen -> sizeof - 1
zeriyoshi cb5f7ae
random: test: fix test readability
zeriyoshi e26f709
Merge remote-tracking branch 'upstream/master' into randomizer_constr…
zeriyoshi da07c17
random: revert sizeof - 1 in randomizer.c
zeriyoshi 8708360
Update NEWS
zeriyoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,36 @@ | ||
--TEST-- | ||
Random: Randomizer: __construct() twice | ||
zeriyoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--FILE-- | ||
<?php | ||
try { | ||
(new \Random\Randomizer())->__construct(); | ||
} catch (\BadMethodCallException $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
try { | ||
(new \Random\Randomizer( | ||
new class () implements \Random\Engine { | ||
public function generate(): string | ||
{ | ||
return \random_bytes(4); /* 32-bit */ | ||
} | ||
} | ||
TimWolla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
))->__construct( | ||
new class () implements \Random\Engine { | ||
public function generate(): string | ||
{ | ||
return \random_bytes(4); /* 32-bit */ | ||
} | ||
} | ||
); | ||
} catch (\BadMethodCallException $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
die('success'); | ||
?> | ||
--EXPECT-- | ||
Cannot call constructor twice | ||
Cannot call constructor twice | ||
success |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this change is related, but that's still
strlen("engine")
in thezend_read_property
call near the end of this filephp-src/ext/random/randomizer.c
Line 282 in e9a447f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. This is a digression from the purpose of this PR, but it was minor and has been corrected.
4afc9db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't bundle unrelated changes into a PR, it distracts from the relevant parts. Can you please revert the
strlen
/sizeof
changes?I also disagree with using
sizeof
in principle: Modern compilers can optimize both. For older compilers the string is very short and it's also not in a hot path.strlen()
is much more readable, because the- 1
is not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
But, the current situation where it is not unified is not so good, so we will create a separate PR to unify it with strlen.