diff options
author | Benny Prijono <bennylp@teluu.com> | 2010-01-29 10:10:49 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2010-01-29 10:10:49 +0000 |
commit | 8e54a92b6eb6302761fd9a1949086baa26e0007a (patch) | |
tree | 7aa9a3938e8fb52cb2970c25ed16e3091af2a9f8 /pjlib/src/pj/pool.c | |
parent | 700fa9dc82720fbca9eacd67b7106ad254595911 (diff) |
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
Diffstat (limited to 'pjlib/src/pj/pool.c')
-rw-r--r-- | pjlib/src/pj/pool.c | 15 |
1 files changed, 13 insertions, 2 deletions
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; } |