Fix GH-23061: SessionHandler::create_sid() failure leaks memory in debug build - #23064
Open
lazerg wants to merge 2 commits into
Open
Fix GH-23061: SessionHandler::create_sid() failure leaks memory in debug build#23064lazerg wants to merge 2 commits into
lazerg wants to merge 2 commits into
Conversation
Girgias
requested changes
Aug 7, 2026
Girgias
reviewed
Aug 7, 2026
Comment on lines
+148
to
+155
| /* The user handler may not have closed the default handler it opened, e.g. because a pending | ||
| * exception prevented its close callback from running at all */ | ||
| if (PS(mod_user_is_open)) { | ||
| zend_try { | ||
| PS(default_mod)->s_close(&PS(mod_data)); | ||
| } zend_end_try(); | ||
| PS(mod_user_is_open) = false; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Yes, different path. This one guards normal shutdown when a user close() never calls parent::close(). The abort() check only covers session_start() failing outright, it never reaches this function.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a save handler extending
SessionHandlerthrows while the session is starting,php_session_abort()calls the user close callback, butzend_call_function()refuses to run userland code while an exception is pending.SessionHandler::close()therefore never runs, and the default handler thatSessionHandler::open()opened stays open, so itsmod_datais never freed. A debug build reports it as two leaks.Since
PS(mod_user_is_open)already tracks whether the default handler is open, request shutdown can close it when the user handler did not. This also covers a handler that overridesclose()without callingparent::close(), which leaked the same way.Fixes GH-23061