smalloc: cleanups and allow sfree(NULL)

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/smalloc.c b/smalloc.c
index 8d1193a..7e6c4f8 100644
--- a/smalloc.c
+++ b/smalloc.c
@@ -336,6 +336,9 @@
 	struct pool *pool = NULL;
 	unsigned int i;
 
+	if (!ptr)
+		return;
+
 	global_read_lock();
 
 	for (i = 0; i < nr_pools; i++) {
@@ -357,14 +360,14 @@
 	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;