acl: use setjmp/longjmp to handle alloc failures at build phase
[dpdk.git] / lib / librte_acl / tb_mem.c
index fdf3080..157e608 100644 (file)
  *  Memory management routines for temporary memory.
  *  That memory is used only during build phase and is released after
  *  build is finished.
+ *  Note, that tb_pool/tb_alloc() are not supposed to return NULL.
+ *  Instead, in the case of failure to allocate memory,
+ *  it would do siglongjmp(pool->fail).
+ *  It is responsibility of the caller to save the proper context/environment,
+ *  in the pool->fail before calling tb_alloc() for the given pool first time.
  */
 
 static struct tb_mem_block *
@@ -51,6 +56,7 @@ tb_pool(struct tb_mem_pool *pool, size_t sz)
        if (block == NULL) {
                RTE_LOG(ERR, MALLOC, "%s(%zu)\n failed, currently allocated "
                        "by pool: %zu bytes\n", __func__, sz, pool->alloc);
+               siglongjmp(pool->fail, -ENOMEM);
                return NULL;
        }
 
@@ -81,8 +87,6 @@ tb_alloc(struct tb_mem_pool *pool, size_t size)
        if (block == NULL || block->size < size) {
                new_sz = (size > pool->min_alloc) ? size : pool->min_alloc;
                block = tb_pool(pool, new_sz);
-               if (block == NULL)
-                       return NULL;
        }
        ptr = block->mem;
        block->size -= size;