[asterisk-scf-commits] asterisk-scf/release/pjproject.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Aug 15 15:28:00 CDT 2012
branch "master" has been updated
via 49c472aaf4813060d74eebd9fae1ac02ecfe9e15 (commit)
from 756114fee0713bc7692cee636cb580b4fd41f28b (commit)
Summary of changes:
pjlib/include/pj/pool.h | 2 +-
pjlib/include/pj/pool_i.h | 2 +-
pjlib/src/pj/pool.c | 4 ++--
pjlib/src/pj/pool_caching.c | 22 +++++++++++++++++++---
4 files changed, 23 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 49c472aaf4813060d74eebd9fae1ac02ecfe9e15
Author: Brent Eagles <beagles at digium.com>
Date: Wed Aug 15 17:56:54 2012 -0230
Fix some overflow issues in pool management and make a bit of code
a bit more clear as to what is going on.
diff --git a/pjlib/include/pj/pool.h b/pjlib/include/pj/pool.h
index a8bdb05..517f6ef 100644
--- a/pjlib/include/pj/pool.h
+++ b/pjlib/include/pj/pool.h
@@ -509,7 +509,7 @@ PJ_INLINE(void*) pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
* Internal functions
*/
PJ_IDECL(void*) pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size);
-PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size);
+PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size);
diff --git a/pjlib/include/pj/pool_i.h b/pjlib/include/pj/pool_i.h
index 1a54be7..48718a7 100644
--- a/pjlib/include/pj/pool_i.h
+++ b/pjlib/include/pj/pool_i.h
@@ -47,7 +47,7 @@ PJ_IDEF(void*) pj_pool_alloc_from_block( pj_pool_block *block, pj_size_t size )
if (size & (PJ_POOL_ALIGNMENT-1)) {
size = (size + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT-1);
}
- if ((unsigned)(block->end - block->cur) >= size) {
+ if ((pj_size_t)(block->end - block->cur) >= size) {
void *ptr = block->cur;
block->cur += size;
return ptr;
diff --git a/pjlib/src/pj/pool.c b/pjlib/src/pj/pool.c
index 4e974ce..cfbc309 100644
--- a/pjlib/src/pj/pool.c
+++ b/pjlib/src/pj/pool.c
@@ -88,7 +88,7 @@ static pj_pool_block *pj_pool_create_block( pj_pool_t *pool, pj_size_t size)
* If no space is available in all the blocks, a new block might be created
* (depending on whether the pool is allowed to resize).
*/
-PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size)
+PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size)
{
pj_pool_block *block = pool->block_list.next;
void *p;
@@ -121,7 +121,7 @@ PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size)
if (pool->increment_size <
size + sizeof(pj_pool_block) + PJ_POOL_ALIGNMENT)
{
- unsigned count;
+ pj_size_t count;
count = (size + pool->increment_size + sizeof(pj_pool_block) +
PJ_POOL_ALIGNMENT) /
pool->increment_size;
diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c
index cf092da..f17e529 100644
--- a/pjlib/src/pj/pool_caching.c
+++ b/pjlib/src/pj/pool_caching.c
@@ -177,8 +177,18 @@ static pj_pool_t* cpool_create_pool(pj_pool_factory *pf,
/* Initialize the pool. */
pj_pool_init_int(pool, name, increment_sz, callback);
- /* Update pool manager's free capacity. */
- cp->capacity -= pj_pool_get_capacity(pool);
+ /* Update pool manager's free capacity.
+ If our free capacity would dip below zero with this pool removed
+ then just set it to zero.
+ */
+ if (cp->capacity > pj_pool_get_capacity(pool))
+ {
+ cp->capacity -= pj_pool_get_capacity(pool);
+ }
+ else
+ {
+ cp->capacity = 0;
+ }
PJ_LOG(6, (pool->obj_name, "pool reused, size=%u", pool->capacity));
}
@@ -199,6 +209,9 @@ static pj_pool_t* cpool_create_pool(pj_pool_factory *pf,
static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool)
{
pj_caching_pool *cp = (pj_caching_pool*)pf;
+ unsigned long currentMaxCapacity = cp->max_capacity;
+ unsigned long currentCapacity = cp->capacity;
+
unsigned pool_capacity;
unsigned i;
@@ -208,6 +221,7 @@ static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool)
pj_lock_acquire(cp->lock);
+
#if PJ_SAFE_POOL
/* Make sure pool is still in our used list */
if (pj_list_find_node(&cp->used_list, pool) != pool) {
@@ -223,13 +237,15 @@ static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool)
--cp->used_count;
pool_capacity = pj_pool_get_capacity(pool);
+ currentCapacity += pool_capacity;
+
/* Destroy the pool if the size is greater than our size or if the total
* capacity in our recycle list (plus the size of the pool) exceeds
* maximum capacity.
. */
if (pool_capacity > pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE-1] ||
- cp->capacity + pool_capacity > cp->max_capacity)
+ currentCapacity > currentMaxCapacity)
{
pj_pool_destroy_int(pool);
pj_lock_release(cp->lock);
-----------------------------------------------------------------------
--
asterisk-scf/release/pjproject.git
More information about the asterisk-scf-commits
mailing list