Skip to content

Commit f458c01

Browse files
committed
Fix bug when new internal buffer not set as last on the pool
1 parent 31f7bcf commit f458c01

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ MemPoolError pool_variable_alloc(VariableMemPool *pool, size_t size, void **ptr)
9292
if (!buffer_has_space(buff, pool->header_size + block_size)) {
9393
buff->next = buffer_new(pool->header_size + max(pool->buff_size, block_size));
9494
buff = buff->next;
95+
pool->buff_last = buff;
9596
}
9697
*ptr = from_buffer(buff, pool->header_size, block_size);
9798
unlock(pool);

test/variable_test.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,34 @@ MU_TEST(test_sizeof)
185185

186186
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_aligned_sizeof(pool, b, &size));
187187
mu_assert_int_eq(mem_align(12), size);
188+
189+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_destroy(pool));
190+
}
191+
192+
MU_TEST(test_multi_blocks)
193+
{
194+
VariableMemPool *pool;
195+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_init(&pool, 1, 10));
196+
197+
void *a, *b, *c;
198+
199+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 60, &a));
200+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 600, &c));
201+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_alloc(pool, 12, &b));
202+
203+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, a));
204+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, b));
205+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_free(pool, c));
206+
207+
mu_assert_int_eq(MEM_POOL_ERR_OK, pool_variable_destroy(pool));
188208
}
189209

190210
void run_variable_pool_test(void)
191211
{
192212
MU_RUN_TEST(test_alloc);
193213
MU_RUN_TEST(test_complex_defragmentation);
194214
MU_RUN_TEST(test_sizeof);
215+
MU_RUN_TEST(test_multi_blocks);
195216

196217
MU_REPORT();
197218
}

0 commit comments

Comments
 (0)