Changeset 809


Ignore:
Timestamp:
Nov 21, 2006 8:36:12 AM (17 years ago)
Author:
bennylp
Message:

Fixed minor memory leak in caching pool (one malloc is not freed)

Location:
pjproject/trunk/pjlib
Files:
2 edited

Legend:

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

    r736 r809  
    796796     * Internal pool. 
    797797     */ 
    798     pj_pool_t      *pool; 
     798    char            pool_buf[256]; 
    799799 
    800800    /** 
    801801     * Mutex. 
    802802     */ 
    803     pj_mutex_t     *mutex; 
     803    pj_lock_t      *lock; 
    804804}; 
    805805 
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r684 r809  
    2121#include <pj/string.h> 
    2222#include <pj/assert.h> 
     23#include <pj/lock.h> 
    2324#include <pj/os.h> 
     25#include <pj/pool_buf.h> 
    2426 
    2527#if !PJ_HAS_POOL_ALT_API 
     
    5355{ 
    5456    int i; 
     57    pj_pool_t *pool; 
    5558 
    5659    PJ_CHECK_STACK(); 
     
    7073    cp->factory.on_block_free = &cpool_on_block_free; 
    7174 
    72     cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 512,  
    73                                   0, NULL); 
    74     i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex); 
     75    pool = pj_pool_create_on_buf("cachingpool", cp->pool_buf, sizeof(cp->pool_buf)); 
     76    pj_lock_create_simple_mutex(pool, "cachingpool", &cp->lock); 
    7577} 
    7678 
     
    102104    } 
    103105 
    104     pj_mutex_destroy(cp->mutex); 
     106    if (cp->lock) { 
     107        pj_lock_destroy(cp->lock); 
     108        pj_lock_create_null_mutex(NULL, "cachingpool", &cp->lock); 
     109    } 
    105110} 
    106111 
     
    117122    PJ_CHECK_STACK(); 
    118123 
    119     pj_mutex_lock(cp->mutex); 
     124    pj_lock_acquire(cp->lock); 
    120125 
    121126    /* Use pool factory's policy when callback is NULL */ 
     
    154159                                  increment_sz, callback); 
    155160        if (!pool) { 
    156             pj_mutex_unlock(cp->mutex); 
     161            pj_lock_release(cp->lock); 
    157162            return NULL; 
    158163        } 
     
    181186    ++cp->used_count; 
    182187 
    183     pj_mutex_unlock(cp->mutex); 
     188    pj_lock_release(cp->lock); 
    184189    return pool; 
    185190} 
     
    193198    PJ_CHECK_STACK(); 
    194199 
    195     pj_mutex_lock(cp->mutex); 
     200    pj_lock_acquire(cp->lock); 
    196201 
    197202    /* Erase from the used list. */ 
     
    211216    { 
    212217        pj_pool_destroy_int(pool); 
    213         pj_mutex_unlock(cp->mutex); 
     218        pj_lock_release(cp->lock); 
    214219        return; 
    215220    } 
     
    232237        /* Something has gone wrong with the pool. */ 
    233238        pj_pool_destroy_int(pool); 
    234         pj_mutex_unlock(cp->mutex); 
     239        pj_lock_release(cp->lock); 
    235240        return; 
    236241    } 
     
    239244    cp->capacity += pool_capacity; 
    240245 
    241     pj_mutex_unlock(cp->mutex); 
     246    pj_lock_release(cp->lock); 
    242247} 
    243248 
     
    247252    pj_caching_pool *cp = (pj_caching_pool*)factory; 
    248253 
    249     pj_mutex_lock(cp->mutex); 
     254    pj_lock_acquire(cp->lock); 
    250255 
    251256    PJ_LOG(3,("cachpool", " Dumping caching pool:")); 
     
    272277    } 
    273278 
    274     pj_mutex_unlock(cp->mutex); 
     279    pj_lock_release(cp->lock); 
    275280#else 
    276281    PJ_UNUSED_ARG(factory); 
Note: See TracChangeset for help on using the changeset viewer.