diff options
author | Yasuo Ohgaki <yohgaki@php.net> | 2015-12-16 09:11:44 +0900 |
---|---|---|
committer | Yasuo Ohgaki <yohgaki@php.net> | 2015-12-16 09:15:05 +0900 |
commit | e8f1c29cc96ce333fa808aba126297b77d94abdf (patch) | |
tree | ab42619e983c00fc5641639f8a8cb546e54b1a5c /ext/session/session.c | |
parent | 838e4039d7fc8f79fe71091725ab0a13a5f4ad2a (diff) | |
download | php-git-e8f1c29cc96ce333fa808aba126297b77d94abdf.tar.gz |
Fixed bug #71122 Session GC may not remove obsolete session data
Diffstat (limited to 'ext/session/session.c')
-rw-r--r-- | ext/session/session.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index 49749219ab..aec2ed06c2 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); } |