/* Mallocs a block of memory and initializes a mempool to use it. */
int mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks, uint32_t block_size, char *name, void **out_buf)
/* Mallocs a block of memory and initializes a mempool to use it. */
int mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks, uint32_t block_size, char *name, void **out_buf)
{
    void *buf;
    int rc;
    rc = mem_malloc_mempool_gen(num_blocks, block_size, &buf);
    if (rc != 0) {
        return rc;
    }
    rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
    if (rc != 0) {
        tls_mem_free(buf);
        return rc;
    }
    if (out_buf != NULL) {
        *out_buf = buf;
    }
    return 0;
}