com php-src: Fixed bug #71122 Session GC may not remove obsolete session data: ext/session/session.c ext/session/tests/bug32330.phpt
ext/session/tests/session_set_save_handler_variation4 .phpt

From: Date: Wed, 16 Dec 2015 00:15:05 +0000
Subject: com php-src: Fixed bug #71122 Session GC may not remove obsolete session data: ext/session/session.c ext/session/tests/bug32330.phpt
ext/session/tests/session_set_save_handler_variation4 .phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90291@lists.php.net to get a copy of this message
Commit: e8f1c29cc96ce333fa808aba126297b77d94abdf Author: Yasuo Ohgaki <yohgaki@php.net> Wed, 16 Dec 2015 09:11:44 +0900 Parents: 838e4039d7fc8f79fe71091725ab0a13a5f4ad2a Branches: PHP-5.6 PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e8f1c29cc96ce333fa808aba126297b77d94abdf Log: Fixed bug #71122 Session GC may not remove obsolete session data Bugs: https://bugs.php.net/71122 Changed paths: M ext/session/session.c M ext/session/tests/bug32330.phpt M ext/session/tests/session_set_save_handler_variation4.phpt Diff: diff --git a/ext/session/session.c b/ext/session/session.c index 4974921..aec2ed0 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -468,6 +468,28 @@ PHPAPI int php_session_valid_key(const char *key) /* {{{ */ } /* }}} */ + +static void php_session_gc(void) /* {{{ */ +{ + int nrand; + + /* GC must be done before reading session data. */ + if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) { + int nrdels = -1; + + nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg(TSRMLS_C)); + if (nrand < PS(gc_probability)) { + PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC); +#ifdef SESSION_DEBUG + if (nrdels != -1) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels); + } +#endif + } + } +} /* }}} */ + + static void php_session_initialize(TSRMLS_D) /* {{{ */ { char *val = NULL; @@ -502,6 +524,9 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */ PS(session_status) = php_session_active; } + /* GC must be done before read */ + php_session_gc(); + /* Read data */ php_session_track_init(TSRMLS_C); if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == FAILURE) { @@ -1490,7 +1515,6 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ zval **ppid; zval **data; char *p, *value; - int nrand; int lensess; if (PS(use_only_cookies)) { @@ -1608,21 +1632,6 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ PS(id) = NULL; } - /* GC must be done before reading session data. */ - if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) { - int nrdels = -1; - - nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg(TSRMLS_C)); - if (nrand < PS(gc_probability)) { - PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC); -#ifdef SESSION_DEBUG - if (nrdels != -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels); - } -#endif - } - } - php_session_initialize(TSRMLS_C); php_session_cache_limiter(TSRMLS_C); } diff --git a/ext/session/tests/bug32330.phpt b/ext/session/tests/bug32330.phpt index 98d442a..fe83cc9 100644 --- a/ext/session/tests/bug32330.phpt +++ b/ext/session/tests/bug32330.phpt @@ -69,17 +69,17 @@ $_SESSION['E'] = 'F'; ?> --EXPECTF-- open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s write: id = %s, data = A|s:1:"B"; close open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s destroy: id = %s close open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s write: id = %s, data = E|s:1:"F"; close diff --git a/ext/session/tests/session_set_save_handler_variation4.phpt b/ext/session/tests/session_set_save_handler_variation4.phpt index 3485f23..6923828 100644 --- a/ext/session/tests/session_set_save_handler_variation4.phpt +++ b/ext/session/tests/session_set_save_handler_variation4.phpt @@ -51,8 +51,8 @@ ob_end_flush(); *** Testing session_set_save_handler() : variation *** Open [%s,PHPSESSID] -Read [%s,%s] GC [0] +Read [%s,%s] array(3) { ["Blah"]=> string(12) "Hello World!" @@ -65,15 +65,9 @@ Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] Close [%s,PHPSESSID] NULL Open [%s,PHPSESSID] -Read [%s,%s] GC [0] -array(3) { - ["Blah"]=> - string(12) "Hello World!" - ["Foo"]=> - bool(false) - ["Guff"]=> - int(1234567890) +Read [%s,%s] +array(0) { } Destroy [%s,%s]

« previous php.cvs (#90291) next »