dmitry Mon Jan 16 09:09:37 2006 UTC
Modified files: (Branch: PHP_5_1)
/TSRM tsrm_virtual_cwd.c tsrm_virtual_cwd.h
/php-src/main main.c
Log:
Fixed bug #36016 (realpath cache memleaks)
http://cvs.php.net/viewcvs.cgi/TSRM/tsrm_virtual_cwd.c?r1=1.74.2.4&r2=1.74.2.5&diff_format=u
Index: TSRM/tsrm_virtual_cwd.c
diff -u TSRM/tsrm_virtual_cwd.c:1.74.2.4 TSRM/tsrm_virtual_cwd.c:1.74.2.5
--- TSRM/tsrm_virtual_cwd.c:1.74.2.4 Sun Jan 1 12:50:00 2006
+++ TSRM/tsrm_virtual_cwd.c Mon Jan 16 09:09:37 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_virtual_cwd.c,v 1.74.2.4 2006/01/01 12:50:00 sniper Exp $ */
+/* $Id: tsrm_virtual_cwd.c,v 1.74.2.5 2006/01/16 09:09:37 dmitry Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -163,18 +163,15 @@
static void cwd_globals_ctor(virtual_cwd_globals *cwd_globals TSRMLS_DC)
{
CWD_STATE_COPY(&cwd_globals->cwd, &main_cwd_state);
-#ifdef REALPATH_CACHE
cwd_globals->realpath_cache_size = 0;
cwd_globals->realpath_cache_size_limit = REALPATH_CACHE_SIZE;
cwd_globals->realpath_cache_ttl = REALPATH_CACHE_TTL;
memset(cwd_globals->realpath_cache, 0,
sizeof(cwd_globals->realpath_cache));
-#endif
}
static void cwd_globals_dtor(virtual_cwd_globals *cwd_globals TSRMLS_DC)
{
CWD_STATE_FREE(&cwd_globals->cwd);
-#ifdef REALPATH_CACHE
{
int i;
@@ -187,7 +184,6 @@
}
}
}
-#endif
}
static char *tsrm_strndup(const char *s, size_t length)
@@ -308,7 +304,6 @@
return buf;
}
-#ifdef REALPATH_CACHE
static inline unsigned long realpath_cache_key(const char *path, int path_len)
{
register unsigned long h;
@@ -343,7 +338,8 @@
}
}
-static inline realpath_cache_bucket* realpath_cache_find(const char *path, int
path_len, time_t t TSRMLS_DC)
+//static inline
+realpath_cache_bucket* realpath_cache_find(const char *path, int path_len,
time_t t TSRMLS_DC)
{
unsigned long key = realpath_cache_key(path, path_len);
unsigned long n = key % (sizeof(CWDG(realpath_cache)) /
sizeof(CWDG(realpath_cache)[0]));
@@ -352,19 +348,18 @@
while (*bucket != NULL) {
if (CWDG(realpath_cache_ttl) && (*bucket)->expires < t) {
realpath_cache_bucket *r = *bucket;
- *bucket = (*bucket)->next;
- CWDG(realpath_cache_size) -= sizeof(realpath_cache_bucket) +
r->path_len + 1 + r->realpath_len + 1;
- free(r);
+ *bucket = (*bucket)->next;
+ CWDG(realpath_cache_size) -=
sizeof(realpath_cache_bucket) + r->path_len + 1 + r->realpath_len + 1;
+ free(r);
} else if (key == (*bucket)->key && path_len ==
(*bucket)->path_len &&
memcmp(path, (*bucket)->path, path_len) == 0) {
return *bucket;
} else {
- *bucket = (*bucket)->next;
+ bucket = &(*bucket)->next;
}
}
return NULL;
}
-#endif
/* Resolve path relatively to state and put the real path into state */
@@ -385,20 +380,17 @@
#else
char *new_path;
#endif
-#ifdef REALPATH_CACHE
char orig_path[MAXPATHLEN];
int orig_path_len;
realpath_cache_bucket *bucket;
time_t t;
TSRMLS_FETCH();
-#endif
if (path_length == 0)
return (0);
if (path_length >= MAXPATHLEN)
return (1);
-#ifdef REALPATH_CACHE
if (use_realpath && CWDG(realpath_cache_size_limit)) {
if (IS_ABSOLUTE_PATH(path, path_length) || (state->cwd_length <
1)) {
memcpy(orig_path, path, path_length+1);
@@ -430,7 +422,6 @@
}
}
}
-#endif
#if !defined(TSRM_WIN32) && !defined(NETWARE)
/* cwd_length can be 0 when getcwd() fails.
* This can happen under solaris when a dir does not have read
permissions
@@ -609,11 +600,9 @@
#endif
free(free_path);
-#ifdef REALPATH_CACHE
if (use_realpath && CWDG(realpath_cache_size_limit)) {
realpath_cache_add(orig_path, orig_path_len, state->cwd,
state->cwd_length, t TSRMLS_CC);
}
-#endif
if (verify_path && verify_path(state)) {
CWD_STATE_FREE(state);
http://cvs.php.net/viewcvs.cgi/TSRM/tsrm_virtual_cwd.h?r1=1.48.2.1&r2=1.48.2.2&diff_format=u
Index: TSRM/tsrm_virtual_cwd.h
diff -u TSRM/tsrm_virtual_cwd.h:1.48.2.1 TSRM/tsrm_virtual_cwd.h:1.48.2.2
--- TSRM/tsrm_virtual_cwd.h:1.48.2.1 Sun Jan 1 12:50:00 2006
+++ TSRM/tsrm_virtual_cwd.h Mon Jan 16 09:09:37 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_virtual_cwd.h,v 1.48.2.1 2006/01/01 12:50:00 sniper Exp $ */
+/* $Id: tsrm_virtual_cwd.h,v 1.48.2.2 2006/01/16 09:09:37 dmitry Exp $ */
#ifndef VIRTUAL_CWD_H
#define VIRTUAL_CWD_H
@@ -195,11 +195,9 @@
CWD_API int virtual_file_ex(cwd_state *state, const char *path,
verify_path_func verify_path, int use_realpath);
-#define REALPATH_CACHE
#define REALPATH_CACHE_TTL (2*60) /* 2 minutes */
#define REALPATH_CACHE_SIZE 0 /* disabled while php.ini isn't loaded */
-#ifdef REALPATH_CACHE
typedef struct _realpath_cache_bucket {
unsigned long key;
char *path;
@@ -209,16 +207,13 @@
time_t expires;
struct _realpath_cache_bucket *next;
} realpath_cache_bucket;
-#endif
typedef struct _virtual_cwd_globals {
cwd_state cwd;
-#ifdef REALPATH_CACHE
long realpath_cache_size;
long realpath_cache_size_limit;
long realpath_cache_ttl;
realpath_cache_bucket *realpath_cache[1024];
-#endif
} virtual_cwd_globals;
#ifdef ZTS
http://cvs.php.net/viewcvs.cgi/php-src/main/main.c?r1=1.640.2.13&r2=1.640.2.14&diff_format=u
Index: php-src/main/main.c
diff -u php-src/main/main.c:1.640.2.13 php-src/main/main.c:1.640.2.14
--- php-src/main/main.c:1.640.2.13 Sun Jan 1 12:50:17 2006
+++ php-src/main/main.c Mon Jan 16 09:09:37 2006
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.640.2.13 2006/01/01 12:50:17 sniper Exp $ */
+/* $Id: main.c,v 1.640.2.14 2006/01/16 09:09:37 dmitry Exp $ */
/* {{{ includes
*/
@@ -322,10 +322,8 @@
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1",
PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen,
php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0",
PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool,
always_populate_raw_post_data, php_core_globals,
core_globals)
-#ifdef REALPATH_CACHE
STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM,
OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM,
OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
-#endif
PHP_INI_END()
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php