1.1 --- a/ucx/mempool.c Mon Mar 06 15:37:40 2017 +0100 1.2 +++ b/ucx/mempool.c Mon Mar 06 16:09:42 2017 +0100 1.3 @@ -93,20 +93,24 @@ 1.4 } 1.5 1.6 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { 1.7 + if (newcap < pool->ndata) { 1.8 + return 1; 1.9 + } 1.10 + 1.11 void **data = (void**) realloc(pool->data, newcap*sizeof(void*)); 1.12 if (data) { 1.13 pool->data = data; 1.14 pool->size = newcap; 1.15 - return EXIT_SUCCESS; 1.16 + return 0; 1.17 } else { 1.18 - return EXIT_FAILURE; 1.19 + return 1; 1.20 } 1.21 } 1.22 1.23 void *ucx_mempool_malloc(UcxMempool *pool, size_t n) { 1.24 if (pool->ndata >= pool->size) { 1.25 - // The hard coded 16 is documented for this function and ucx_mempool_new 1.26 - if (ucx_mempool_chcap(pool, pool->size + 16) == EXIT_FAILURE) { 1.27 + if (pool->size*2 < pool->size /* overflow check */ 1.28 + || ucx_mempool_chcap(pool, pool->size*2)) { 1.29 return NULL; 1.30 } 1.31 } 1.32 @@ -147,7 +151,7 @@ 1.33 } 1.34 fprintf(stderr, "FATAL: 0x%08" PRIxPTR" not in mpool 0x%08" PRIxPTR"\n", 1.35 (intptr_t)ptr, (intptr_t)pool); 1.36 - exit(EXIT_FAILURE); 1.37 + abort(); 1.38 } else { 1.39 return newm + sizeof(ucx_destructor); 1.40 }