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_new.cpp

    r1235 r1333  
    2626 * This file contains pool default policy definition and implementation. 
    2727 */ 
     28#include "pool_signature.h" 
    2829  
    2930 
    3031static void *operator_new(pj_pool_factory *factory, pj_size_t size) 
    3132{ 
     33    void *mem; 
     34 
    3235    PJ_CHECK_STACK(); 
    3336    PJ_UNUSED_ARG(factory); 
    3437    PJ_UNUSED_ARG(size); 
    3538 
    36     return new char[size]; 
     39    mem = (void*) new char[size+(SIG_SIZE << 1)]; 
     40     
     41    /* Exception for new operator may be disabled, so.. */ 
     42    if (mem) { 
     43        /* Apply signature when PJ_SAFE_POOL is set. It will move 
     44         * "mem" pointer forward. 
     45         */ 
     46        APPLY_SIG(mem, size); 
     47    } 
     48 
     49    return mem; 
    3750} 
    3851 
     
    4255    PJ_UNUSED_ARG(factory); 
    4356    PJ_UNUSED_ARG(size); 
     57 
     58    /* Check and remove signature when PJ_SAFE_POOL is set. It will 
     59     * move "mem" pointer backward. 
     60     */ 
     61    REMOVE_SIG(mem, size); 
     62 
     63    /* Note that when PJ_SAFE_POOL is set, the actual size of the block 
     64     * is size + SIG_SIZE*2. 
     65     */ 
    4466 
    4567    char *p = (char*)mem; 
Note: See TracChangeset for help on using the changeset viewer.