From 32069e953f8acffc3041bc70f5c2a3c98769490f Mon Sep 17 00:00:00 2001 From: Xuefer Date: Thu, 31 Aug 2006 23:45:54 +0000 Subject: [PATCH] fix leak in xcache.test=1; XCACHE_VERSION/XCACHE_MODULES length off-by-one git-svn-id: svn://svn.lighttpd.net/xcache/trunk@119 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- mmap.c | 11 +++++++++++ xcache.c | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mmap.c b/mmap.c index 8e3bd64..81c37c9 100644 --- a/mmap.c +++ b/mmap.c @@ -152,6 +152,7 @@ xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_pr int ro_ok; volatile void *romem; char tmpname[sizeof(TMP_PATH) - 1 + 100]; + const char *errstr = NULL; CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM"); shm->size = size; @@ -177,11 +178,15 @@ xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_pr if (fd == -1) { /* do not create file in /dev */ if (strncmp(shm->name, "/dev", 4) == 0) { + perror(shm->name); + errstr = "Cannot open file set by xcache.mmap_path"; goto err; } fd = open(shm->name, O_CREAT | O_RDWR, XCACHE_MMAP_PERMISSION); shm->newfile = 1; if (fd == -1) { + perror(shm->name); + errstr = "Cannot open or create file set by xcache.mmap_path"; goto err; } } @@ -196,6 +201,8 @@ xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_pr #endif if (shm->ptr == XCACHE_MAP_FAILED) { + perror(shm->name); + errstr = "Failed creating file mappping"; shm->ptr = NULL; goto err; } @@ -267,6 +274,10 @@ err: if (shm) { xc_shm_destroy(shm); } + if (errstr) { + fprintf(stderr, "%s\n", errstr); + zend_error(E_ERROR, "%s", errstr); + } return NULL; } /* }}} */ diff --git a/xcache.c b/xcache.c index 8d1fcdf..09c0dcf 100644 --- a/xcache.c +++ b/xcache.c @@ -938,6 +938,8 @@ err_bailout: zend_bailout(); } if (xc_test && stored_xce) { + destroy_op_array(op_array TSRMLS_CC); + efree(op_array); goto restore; } return op_array; @@ -1064,8 +1066,8 @@ static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */ zend_register_long_constant(ZEND_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); zend_register_long_constant(ZEND_STRS("XC_TYPE_PHP"), XC_TYPE_PHP, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); zend_register_long_constant(ZEND_STRS("XC_TYPE_VAR"), XC_TYPE_VAR, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); - zend_register_stringl_constant(ZEND_STRS("XCACHE_VERSION"), ZEND_STRS(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); - zend_register_stringl_constant(ZEND_STRS("XCACHE_MODULES"), ZEND_STRS(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); + zend_register_stringl_constant(ZEND_STRS("XCACHE_VERSION"), ZEND_STRL(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); + zend_register_stringl_constant(ZEND_STRS("XCACHE_MODULES"), ZEND_STRL(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); return 0; } /* }}} */