diff options
author | David Wragg <david@rabbitmq.com> | 2010-09-03 10:18:55 +0100 |
---|---|---|
committer | David Wragg <david@rabbitmq.com> | 2010-09-03 10:18:55 +0100 |
commit | b85fa81a4076536048ea374094dccbd580a5fe6e (patch) | |
tree | 7985515d5dd7925706eaa82623449b6eaa053b7a /librabbitmq/amqp_mem.c | |
parent | b339e621a8a85fbd749fdb499161320abed5ebb3 (diff) | |
parent | 1b1340ad50e18edc194f26a7156cab44b8a1bba0 (diff) | |
download | rabbitmq-c-github-ask-bug22951.tar.gz |
Merge amqp_0_9_1 into bug22951 to remove headbug22951
Diffstat (limited to 'librabbitmq/amqp_mem.c')
-rw-r--r-- | librabbitmq/amqp_mem.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/librabbitmq/amqp_mem.c b/librabbitmq/amqp_mem.c index 6e52dc8..021151a 100644 --- a/librabbitmq/amqp_mem.c +++ b/librabbitmq/amqp_mem.c @@ -53,7 +53,6 @@ #include <string.h> #include <stdint.h> #include <sys/types.h> -#include <errno.h> #include <assert.h> #include "amqp.h" @@ -102,25 +101,24 @@ void empty_amqp_pool(amqp_pool_t *pool) { empty_blocklist(&pool->pages); } +/* Returns 1 on success, 0 on failure */ static int record_pool_block(amqp_pool_blocklist_t *x, void *block) { size_t blocklistlength = sizeof(void *) * (x->num_blocks + 1); if (x->blocklist == NULL) { x->blocklist = malloc(blocklistlength); - if (x->blocklist == NULL) { - return -ENOMEM; - } + if (x->blocklist == NULL) + return 0; } else { void *newbl = realloc(x->blocklist, blocklistlength); - if (newbl == NULL) { - return -ENOMEM; - } + if (newbl == NULL) + return 0; x->blocklist = newbl; } x->blocklist[x->num_blocks] = block; x->num_blocks++; - return 0; + return 1; } void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount) { @@ -135,9 +133,8 @@ void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount) { if (result == NULL) { return NULL; } - if (record_pool_block(&pool->large_blocks, result) != 0) { + if (!record_pool_block(&pool->large_blocks, result)) return NULL; - } return result; } @@ -156,9 +153,8 @@ void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount) { if (pool->alloc_block == NULL) { return NULL; } - if (record_pool_block(&pool->pages, pool->alloc_block) != 0) { + if (!record_pool_block(&pool->pages, pool->alloc_block)) return NULL; - } pool->next_page = pool->pages.num_blocks; } else { pool->alloc_block = pool->pages.blocklist[pool->next_page]; |