Merge pull request #2451 from libgit2/rb/round-up-pool-allocations Round up pool alloc sizes for alignment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/pool.c b/src/pool.c
index 146f118..a516ff9 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -146,7 +146,7 @@ GIT_INLINE(void) pool_remove_page(
void *git_pool_malloc(git_pool *pool, uint32_t items)
{
git_pool_page *scan = pool->open, *prev;
- uint32_t size = items * pool->item_size;
+ uint32_t size = ((items * pool->item_size) + 7) & ~7;
void *ptr = NULL;
pool->has_string_alloc = 0;
diff --git a/tests/core/pool.c b/tests/core/pool.c
index 351d0c2..a7ec880 100644
--- a/tests/core/pool.c
+++ b/tests/core/pool.c
@@ -38,19 +38,19 @@ void test_core_pool__1(void)
cl_assert(git_pool_malloc(&p, i) != NULL);
/* with fixed page size, allocation must end up with these values */
- cl_assert(git_pool__open_pages(&p) == 1);
- cl_assert(git_pool__full_pages(&p) == 505);
+ cl_assert_equal_i(1, git_pool__open_pages(&p));
+ cl_assert_equal_i(507, git_pool__full_pages(&p));
git_pool_clear(&p);
- cl_git_pass(git_pool_init(&p, 1, 4100));
+ cl_git_pass(git_pool_init(&p, 1, 4120));
for (i = 2010; i > 0; i--)
cl_assert(git_pool_malloc(&p, i) != NULL);
/* with fixed page size, allocation must end up with these values */
- cl_assert(git_pool__open_pages(&p) == 1);
- cl_assert(git_pool__full_pages(&p) == 492);
+ cl_assert_equal_i(1, git_pool__open_pages(&p));
+ cl_assert_equal_i(492, git_pool__full_pages(&p));
git_pool_clear(&p);
}