Changeset 2963


Ignore:
Timestamp:
10/23/09 21:06:40 (9 years ago)
Author:
bennylp
Message:

Fixed ticket #980: Memory pool alignment error when alignment is set to be greater than 4 bytes (thanks John Ridges for the report)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/pool.c

    r2394 r2963  
    6767    pool->capacity += size; 
    6868 
    69     /* Set block attribytes. */ 
    70     block->cur = block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); 
     69    /* Set start and end of buffer. */ 
     70    block->buf = ((unsigned char*)block) + sizeof(pj_pool_block); 
    7171    block->end = ((unsigned char*)block) + size; 
     72 
     73    /* Set the start pointer, aligning it as needed */ 
     74    block->cur = (unsigned char*) 
     75                 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &  
     76                  ~(PJ_POOL_ALIGNMENT - 1)); 
    7277 
    7378    /* Insert in the front of the list. */ 
     
    112117    /* If pool is configured to expand, but the increment size 
    113118     * is less than the required size, expand the pool by multiple 
    114      * increment size 
     119     * increment size. Also count the size wasted due to aligning 
     120     * the block. 
    115121     */ 
    116     if (pool->increment_size < size + sizeof(pj_pool_block)) { 
     122    if (pool->increment_size <  
     123            size + sizeof(pj_pool_block) + PJ_POOL_ALIGNMENT)  
     124    { 
    117125        unsigned count; 
    118         count = (size + pool->increment_size + sizeof(pj_pool_block)) /  
     126        count = (size + pool->increment_size + sizeof(pj_pool_block) + 
     127                 PJ_POOL_ALIGNMENT) /  
    119128                pool->increment_size; 
    120129        block_size = count * pool->increment_size; 
Note: See TracChangeset for help on using the changeset viewer.