Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ PHP NEWS
. Fix corruption in mod_mm. (ndossche)
. Fixed bug GH-23043 (broken session id code can cause zend_mm_heap
corrupted). (ndossche)
. Fixed bug GH-23061 (SessionHandler::create_sid() callback failure leaks
memory in debug build). (Lazizbek Ergashev)

- Sockets:
. Fixed various memory related issues in ext/sockets. (David Carlier)
Expand Down
8 changes: 8 additions & 0 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ static void php_rshutdown_session_globals(void) /* {{{ */
PS(mod)->s_close(&PS(mod_data));
} zend_end_try();
}
/* 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;
}
if (PS(id)) {
zend_string_release_ex(PS(id), 0);
PS(id) = NULL;
Expand Down
21 changes: 21 additions & 0 deletions ext/session/tests/user_session_module/gh23061.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-23061 (SessionHandler::create_sid() callback failure leaks memory in debug build)
--EXTENSIONS--
session
--FILE--
<?php
class a extends SessionHandler {
function create_sid(): string {
return [3, 6];
}
}
$c = new a;
session_set_save_handler($c);
try {
session_start();
} catch (Error $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}
?>
--EXPECT--
Error: Session id must be a string
Loading