diff --git a/src/variable.c b/src/variable.c index 20ad2dc..24499d7 100644 --- a/src/variable.c +++ b/src/variable.c @@ -92,6 +92,7 @@ MemPoolError pool_variable_alloc(VariableMemPool *pool, size_t size, void **ptr) if (!buffer_has_space(buff, pool->header_size + block_size)) { buff->next = buffer_new(pool->header_size + max(pool->buff_size, block_size)); buff = buff->next; + pool->buff_last = buff; } *ptr = from_buffer(buff, pool->header_size, block_size); unlock(pool); diff --git a/test/variable_test.c b/test/variable_test.c index b66ee96..c039fa9 100644 --- a/test/variable_test.c +++ b/test/variable_test.c @@ -185,6 +185,26 @@ MU_TEST(test_sizeof) mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_aligned_sizeof(pool, b, &size)); mu_assert_int_eq(mem_align(12), size); + + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_destroy(pool)); +} + +MU_TEST(test_multi_blocks) +{ + VariableMemPool *pool; + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_init(&pool, 1, 10)); + + void *a, *b, *c; + + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 60, &a)); + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 600, &c)); + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 12, &b)); + + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, a)); + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, b)); + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, c)); + + mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_destroy(pool)); } void run_variable_pool_test(void) @@ -192,6 +212,7 @@ void run_variable_pool_test(void) MU_RUN_TEST(test_alloc); MU_RUN_TEST(test_complex_defragmentation); MU_RUN_TEST(test_sizeof); + MU_RUN_TEST(test_multi_blocks); MU_REPORT(); }