Skip to content

Commit

Permalink
Fix bug when new internal buffer not set as last on the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Isty001 committed May 11, 2019
1 parent 31f7bcf commit f458c01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions test/variable_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,34 @@ 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)
{
MU_RUN_TEST(test_alloc);
MU_RUN_TEST(test_complex_defragmentation);
MU_RUN_TEST(test_sizeof);
MU_RUN_TEST(test_multi_blocks);

MU_REPORT();
}

0 comments on commit f458c01

Please sign in to comment.