From 8e54a92b6eb6302761fd9a1949086baa26e0007a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 29 Jan 2010 10:10:49 +0000 Subject: Fixed ticket #1037: Memory pool alignment error when alignment is set to be greater than the default (thanks John Ridges for the report): - fixed the pool allocation routines in PJLIB, - add alignment test in pjlib-test (only useful if PJ_POOL_ALIGNMENT is configured in config_site.h), - fixed other pool tests in pjlib-test which are broken when PJ_POOL_ALIGNMENT is enlarged git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3081 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/pool.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'pjlib/src/pj/pool.c') diff --git a/pjlib/src/pj/pool.c b/pjlib/src/pj/pool.c index 5b022a8c..22df21c6 100644 --- a/pjlib/src/pj/pool.c +++ b/pjlib/src/pj/pool.c @@ -212,8 +212,14 @@ PJ_DEF(pj_pool_t*) pj_pool_create_int( pj_pool_factory *f, const char *name, /* Create the first block from the memory. */ block = (pj_pool_block*) (buffer + sizeof(*pool)); - block->cur = block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); + block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); block->end = buffer + initial_size; + + /* Set the start pointer, aligning it as needed */ + block->cur = (unsigned char*) + (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & + ~(PJ_POOL_ALIGNMENT - 1)); + pj_list_insert_after(&pool->block_list, block); pj_pool_init_int(pool, name, increment_size, callback); @@ -254,7 +260,12 @@ static void reset_pool(pj_pool_t *pool) } block = pool->block_list.next; - block->cur = block->buf; + + /* Set the start pointer, aligning it as needed */ + block->cur = (unsigned char*) + (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & + ~(PJ_POOL_ALIGNMENT - 1)); + pool->capacity = block->end - (unsigned char*)pool; } -- cgit v1.2.3