Ignore:
Timestamp:
Jun 1, 2007 7:26:21 AM (17 years ago)
Author:
bennylp
Message:

Implement ticket #314: Added PJ_SAFE_POOL configuration in PJLIB to track down memory corruptions

File:
1 edited

Legend:

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

    r974 r1333  
    2727 * This file contains pool default policy definition and implementation. 
    2828 */ 
     29#include "pool_signature.h" 
    2930 
    3031 
     
    4243    } 
    4344 
    44     p = malloc(size); 
     45    p = malloc(size+(SIG_SIZE << 1)); 
    4546 
    4647    if (p == NULL) { 
    4748        if (factory->on_block_free)  
    4849            factory->on_block_free(factory, size); 
     50    } else { 
     51        /* Apply signature when PJ_SAFE_POOL is set. It will move 
     52         * "p" pointer forward. 
     53         */ 
     54        APPLY_SIG(p, size); 
    4955    } 
    5056 
     
    5965    if (factory->on_block_free)  
    6066        factory->on_block_free(factory, size); 
     67 
     68    /* Check and remove signature when PJ_SAFE_POOL is set. It will 
     69     * move "mem" pointer backward. 
     70     */ 
     71    REMOVE_SIG(mem, size); 
     72 
     73    /* Note that when PJ_SAFE_POOL is set, the actual size of the block 
     74     * is size + SIG_SIZE*2. 
     75     */ 
    6176 
    6277    free(mem); 
Note: See TracChangeset for help on using the changeset viewer.