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

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@809 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c
index d90e167..b0d2795 100644
--- a/pjlib/src/pj/pool_caching.c
+++ b/pjlib/src/pj/pool_caching.c
@@ -20,7 +20,9 @@
 #include <pj/log.h>
 #include <pj/string.h>
 #include <pj/assert.h>
+#include <pj/lock.h>
 #include <pj/os.h>
+#include <pj/pool_buf.h>
 
 #if !PJ_HAS_POOL_ALT_API
 
@@ -52,6 +54,7 @@
 				   pj_size_t max_capacity)
 {
     int i;
+    pj_pool_t *pool;
 
     PJ_CHECK_STACK();
 
@@ -69,9 +72,8 @@
     cp->factory.on_block_alloc = &cpool_on_block_alloc;
     cp->factory.on_block_free = &cpool_on_block_free;
 
-    cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 512, 
-				  0, NULL);
-    i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex);
+    pool = pj_pool_create_on_buf("cachingpool", cp->pool_buf, sizeof(cp->pool_buf));
+    pj_lock_create_simple_mutex(pool, "cachingpool", &cp->lock);
 }
 
 PJ_DEF(void) pj_caching_pool_destroy( pj_caching_pool *cp )
@@ -101,7 +103,10 @@
 	pool = next;
     }
 
-    pj_mutex_destroy(cp->mutex);
+    if (cp->lock) {
+	pj_lock_destroy(cp->lock);
+	pj_lock_create_null_mutex(NULL, "cachingpool", &cp->lock);
+    }
 }
 
 static pj_pool_t* cpool_create_pool(pj_pool_factory *pf, 
@@ -116,7 +121,7 @@
 
     PJ_CHECK_STACK();
 
-    pj_mutex_lock(cp->mutex);
+    pj_lock_acquire(cp->lock);
 
     /* Use pool factory's policy when callback is NULL */
     if (callback == NULL) {
@@ -153,7 +158,7 @@
 	pool = pj_pool_create_int(&cp->factory, name, initial_size, 
 				  increment_sz, callback);
 	if (!pool) {
-	    pj_mutex_unlock(cp->mutex);
+	    pj_lock_release(cp->lock);
 	    return NULL;
 	}
 
@@ -180,7 +185,7 @@
     /* Increment used count. */
     ++cp->used_count;
 
-    pj_mutex_unlock(cp->mutex);
+    pj_lock_release(cp->lock);
     return pool;
 }
 
@@ -192,7 +197,7 @@
 
     PJ_CHECK_STACK();
 
-    pj_mutex_lock(cp->mutex);
+    pj_lock_acquire(cp->lock);
 
     /* Erase from the used list. */
     pj_list_erase(pool);
@@ -210,7 +215,7 @@
 	cp->capacity + pool_capacity > cp->max_capacity)
     {
 	pj_pool_destroy_int(pool);
-	pj_mutex_unlock(cp->mutex);
+	pj_lock_release(cp->lock);
 	return;
     }
 
@@ -231,14 +236,14 @@
     if (i >= PJ_CACHING_POOL_ARRAY_SIZE ) {
 	/* Something has gone wrong with the pool. */
 	pj_pool_destroy_int(pool);
-	pj_mutex_unlock(cp->mutex);
+	pj_lock_release(cp->lock);
 	return;
     }
 
     pj_list_insert_after(&cp->free_list[i], pool);
     cp->capacity += pool_capacity;
 
-    pj_mutex_unlock(cp->mutex);
+    pj_lock_release(cp->lock);
 }
 
 static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail )
@@ -246,7 +251,7 @@
 #if PJ_LOG_MAX_LEVEL >= 3
     pj_caching_pool *cp = (pj_caching_pool*)factory;
 
-    pj_mutex_lock(cp->mutex);
+    pj_lock_acquire(cp->lock);
 
     PJ_LOG(3,("cachpool", " Dumping caching pool:"));
     PJ_LOG(3,("cachpool", "   Capacity=%u, max_capacity=%u, used_cnt=%u", \
@@ -271,7 +276,7 @@
 			      total_used * 100 / total_capacity));
     }
 
-    pj_mutex_unlock(cp->mutex);
+    pj_lock_release(cp->lock);
 #else
     PJ_UNUSED_ARG(factory);
     PJ_UNUSED_ARG(detail);