summaryrefslogtreecommitdiff
path: root/xcache
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2013-09-23 09:51:43 +0000
committerXuefer <xuefer@gmail.com>2013-09-23 09:51:43 +0000
commit74214f82e41509fb20ce6b8def9db7a2588ddeff (patch)
treeb77943473acae47f551539d0657db3b2760a0ab1 /xcache
parentf7035318b77a345d4e580a77ef4f2cfdd9501045 (diff)
downloadxcache-74214f82e41509fb20ce6b8def9db7a2588ddeff.tar.gz
xcache-74214f82e41509fb20ce6b8def9db7a2588ddeff.zip
calc avail for test
git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1392 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
Diffstat (limited to 'xcache')
-rw-r--r--xcache/xc_malloc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/xcache/xc_malloc.c b/xcache/xc_malloc.c
index 5c48ed1..4ac19b6 100644
--- a/xcache/xc_malloc.c
+++ b/xcache/xc_malloc.c
@@ -38,9 +38,8 @@ struct _xc_malloc_shm_t {
static void *xc_add_to_blocks(xc_allocator_t *allocator, void *p, size_t size) /* {{{ */
{
if (p) {
-#ifdef TEST
allocator->avail -= size;
-#else
+#ifndef TEST
zend_hash_add(&allocator->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL);
#endif
}
@@ -59,6 +58,9 @@ static void xc_del_from_blocks(xc_allocator_t *allocator, void *p) /* {{{ */
static XC_ALLOCATOR_MALLOC(xc_allocator_malloc_malloc) /* {{{ */
{
+ if (allocator->avail < size) {
+ return NULL;
+ }
return xc_add_to_blocks(allocator, malloc(size), size);
}
/* }}} */
@@ -71,6 +73,9 @@ static XC_ALLOCATOR_FREE(xc_allocator_malloc_free) /* {{{ return block size free
/* }}} */
static XC_ALLOCATOR_CALLOC(xc_allocator_malloc_calloc) /* {{{ */
{
+ if (allocator->avail < size) {
+ return NULL;
+ }
return xc_add_to_blocks(allocator, calloc(memb, size), size);
}
/* }}} */