summaryrefslogtreecommitdiff
path: root/smalloc.c
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2008-04-16 19:51:46 +0200
committerJens Axboe <jens.axboe@oracle.com>2008-04-16 19:51:46 +0200
commit8e5732e558509fc0f4ccdeb1e4d01ad038aead06 (patch)
tree8a59eadffc930e5c86f18695ac0b447710b8c72e /smalloc.c
parentc08e194db676bd9dcd0f43bacf2051c7c91a62df (diff)
downloadfio-8e5732e558509fc0f4ccdeb1e4d01ad038aead06.tar.gz
smalloc: cleanups and allow sfree(NULL)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'smalloc.c')
-rw-r--r--smalloc.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/smalloc.c b/smalloc.c
index 8d1193ab..7e6c4f8f 100644
--- a/smalloc.c
+++ b/smalloc.c
@@ -336,6 +336,9 @@ void sfree(void *ptr)
struct pool *pool = NULL;
unsigned int i;
+ if (!ptr)
+ return;
+
global_read_lock();
for (i = 0; i < nr_pools; i++) {
@@ -357,14 +360,14 @@ static void *smalloc_pool(struct pool *pool, unsigned int size)
int did_restart = 0;
void *ret;
- /*
- * slight chance of race with sfree() here, but acceptable
- */
- if (!size || size > pool->room + sizeof(*hdr) ||
- ((size > pool->largest_block) && pool->largest_block))
+ if (!size)
return NULL;
pool_lock(pool);
+ if (size > pool->room + sizeof(*hdr))
+ goto fail;
+ if ((size > pool->largest_block) && pool->largest_block)
+ goto fail;
restart:
hdr = pool->last;
prv = NULL;