Changeset 4298 for pjproject


Ignore:
Timestamp:
Nov 22, 2012 5:00:01 AM (12 years ago)
Author:
nanang
Message:

Fix #1593: avoid wrap around in caching pool capacity value.

Location:
pjproject/trunk/pjlib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/pool.h

    r3553 r4298  
    510510 */ 
    511511PJ_IDECL(void*) pj_pool_alloc_from_block(pj_pool_block *block, pj_size_t size); 
    512 PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size); 
     512PJ_DECL(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size); 
    513513 
    514514 
  • pjproject/trunk/pjlib/include/pj/pool_i.h

    r3553 r4298  
    4848        size = (size + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT-1); 
    4949    } 
    50     if ((unsigned)(block->end - block->cur) >= size) { 
     50    if ((pj_size_t)(block->end - block->cur) >= size) { 
    5151        void *ptr = block->cur; 
    5252        block->cur += size; 
  • pjproject/trunk/pjlib/src/pj/pool.c

    r3553 r4298  
    8989 * (depending on whether the pool is allowed to resize). 
    9090 */ 
    91 PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, unsigned size) 
     91PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size) 
    9292{ 
    9393    pj_pool_block *block = pool->block_list.next; 
     
    122122            size + sizeof(pj_pool_block) + PJ_POOL_ALIGNMENT)  
    123123    { 
    124         unsigned count; 
     124        pj_size_t count; 
    125125        count = (size + pool->increment_size + sizeof(pj_pool_block) + 
    126126                 PJ_POOL_ALIGNMENT) /  
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r3553 r4298  
    179179 
    180180        /* Update pool manager's free capacity. */ 
    181         cp->capacity -= pj_pool_get_capacity(pool); 
     181        if (cp->capacity > pj_pool_get_capacity(pool)) { 
     182            cp->capacity -= pj_pool_get_capacity(pool); 
     183        } else { 
     184            cp->capacity = 0; 
     185        } 
    182186 
    183187        PJ_LOG(6, (pool->obj_name, "pool reused, size=%u", pool->capacity)); 
     
    200204{ 
    201205    pj_caching_pool *cp = (pj_caching_pool*)pf; 
    202     unsigned pool_capacity; 
     206    pj_size_t pool_capacity; 
    203207    unsigned i; 
    204208 
Note: See TracChangeset for help on using the changeset viewer.