Skip to content

Commit 2ddd68a

Browse files
committed
Free handles by name directly
1 parent 5b40d06 commit 2ddd68a

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

ext/session/session.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,6 +2775,13 @@ static PHP_RINIT_FUNCTION(session) /* {{{ */
27752775
}
27762776
/* }}} */
27772777

2778+
#define SESSION_FREE_USER_HANDLER(struct_name) \
2779+
if (!Z_ISUNDEF(PS(mod_user_names).name.struct_name)) { \
2780+
zval_ptr_dtor(&PS(mod_user_names).name.struct_name); \
2781+
ZVAL_UNDEF(&PS(mod_user_names).name.struct_name); \
2782+
}
2783+
2784+
27782785
static PHP_RSHUTDOWN_FUNCTION(session) /* {{{ */
27792786
{
27802787
if (PS(session_status) == php_session_active) {
@@ -2785,12 +2792,16 @@ static PHP_RSHUTDOWN_FUNCTION(session) /* {{{ */
27852792
php_rshutdown_session_globals();
27862793

27872794
/* this should NOT be done in php_rshutdown_session_globals() */
2788-
for (int i = 0; i < PS_NUM_APIS; i++) {
2789-
if (!Z_ISUNDEF(PS(mod_user_names).names[i])) {
2790-
zval_ptr_dtor(&PS(mod_user_names).names[i]);
2791-
ZVAL_UNDEF(&PS(mod_user_names).names[i]);
2792-
}
2793-
}
2795+
/* Free user defined handlers */
2796+
SESSION_FREE_USER_HANDLER(ps_open);
2797+
SESSION_FREE_USER_HANDLER(ps_close);
2798+
SESSION_FREE_USER_HANDLER(ps_read);
2799+
SESSION_FREE_USER_HANDLER(ps_write);
2800+
SESSION_FREE_USER_HANDLER(ps_destroy);
2801+
SESSION_FREE_USER_HANDLER(ps_gc);
2802+
SESSION_FREE_USER_HANDLER(ps_create_sid);
2803+
SESSION_FREE_USER_HANDLER(ps_validate_sid);
2804+
SESSION_FREE_USER_HANDLER(ps_update_timestamp);
27942805

27952806
return SUCCESS;
27962807
}
@@ -2815,9 +2826,16 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */
28152826
ps_globals->mod_user_is_open = 0;
28162827
ps_globals->session_vars = NULL;
28172828
ps_globals->set_handler = 0;
2818-
for (int i = 0; i < PS_NUM_APIS; i++) {
2819-
ZVAL_UNDEF(&ps_globals->mod_user_names.names[i]);
2820-
}
2829+
/* Unset user defined handlers */
2830+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_open);
2831+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_close);
2832+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_read);
2833+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_write);
2834+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_destroy);
2835+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_gc);
2836+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_create_sid);
2837+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_validate_sid);
2838+
ZVAL_UNDEF(&ps_globals->mod_user_names.name.ps_update_timestamp);
28212839
ZVAL_UNDEF(&ps_globals->http_session_vars);
28222840
}
28232841
/* }}} */

0 commit comments

Comments
 (0)