Index: /pjproject/trunk/pjlib-util/src/pjlib-util/dns_server.c
===================================================================
--- /pjproject/trunk/pjlib-util/src/pjlib-util/dns_server.c	(revision 5533)
+++ /pjproject/trunk/pjlib-util/src/pjlib-util/dns_server.c	(revision 5534)
@@ -125,9 +125,5 @@
     }
 
-    if (srv->pool) {
-	pj_pool_t *pool = srv->pool;
-	srv->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&srv->pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
===================================================================
--- /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 5533)
+++ /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 5534)
@@ -514,9 +514,6 @@
     }
 
-    if (resolver->pool) {
-	pj_pool_t *pool = resolver->pool;
-	resolver->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&resolver->pool);
+
     return PJ_SUCCESS;
 }
Index: /pjproject/trunk/pjlib/include/pj/pool_i.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/pool_i.h	(revision 5533)
+++ /pjproject/trunk/pjlib/include/pj/pool_i.h	(revision 5534)
@@ -98,4 +98,5 @@
     pj_pool_t *pool = *ppool;
     *ppool = NULL;
-    pj_pool_release(pool);
+    if (pool)
+	pj_pool_release(pool);
 }
Index: /pjproject/trunk/pjmedia/src/pjmedia-audiodev/legacy_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-audiodev/legacy_dev.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia-audiodev/legacy_dev.c	(revision 5534)
@@ -142,7 +142,5 @@
 
     if (status == PJ_SUCCESS) {
-	pj_pool_t *pool = wf->pool;
-	wf->pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&wf->pool);
     }
 
@@ -456,8 +454,5 @@
 
     if (status == PJ_SUCCESS) {
-	pj_pool_t *pool = strm->pool;
-
-	strm->pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&strm->pool);
     }
 
Index: /pjproject/trunk/pjmedia/src/pjmedia-audiodev/null_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-audiodev/null_dev.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia-audiodev/null_dev.c	(revision 5534)
@@ -161,8 +161,6 @@
 {
     struct null_audio_factory *nf = (struct null_audio_factory*)f;
-    pj_pool_t *pool = nf->pool;
-
-    nf->pool = NULL;
-    pj_pool_release(pool);
+
+    pj_pool_safe_release(&nf->pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjmedia/src/pjmedia-videodev/avi_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-videodev/avi_dev.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia-videodev/avi_dev.c	(revision 5534)
@@ -193,8 +193,6 @@
 {
     struct avi_factory *cf = (struct avi_factory*)f;
-    pj_pool_t *pool = cf->pool;
-
-    cf->pool = NULL;
-    pj_pool_release(pool);
+
+    pj_pool_safe_release(&cf->pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjmedia/src/pjmedia-videodev/colorbar_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-videodev/colorbar_dev.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia-videodev/colorbar_dev.c	(revision 5534)
@@ -253,8 +253,6 @@
 {
     struct cbar_factory *cf = (struct cbar_factory*)f;
-    pj_pool_t *pool = cf->pool;
-
-    cf->pool = NULL;
-    pj_pool_release(pool);
+
+    pj_pool_safe_release(&cf->pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjmedia/src/pjmedia/clock_thread.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/clock_thread.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia/clock_thread.c	(revision 5534)
@@ -416,11 +416,8 @@
     }
 
-    if (clock->pool) {
-	pj_pool_t *pool = clock->pool;
-	clock->pool = NULL;
-	pj_pool_release(pool);
-    }
-    return PJ_SUCCESS;
-}
-
-
+    pj_pool_safe_release(&clock->pool);
+
+    return PJ_SUCCESS;
+}
+
+
Index: /pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 5534)
@@ -2572,9 +2572,6 @@
 #endif
 
-    if (stream->own_pool) {
-	pj_pool_t *pool = stream->own_pool;
-	stream->own_pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&stream->own_pool);
+
     return PJ_SUCCESS;
 }
Index: /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 5534)
@@ -1879,9 +1879,5 @@
     }
 
-    if (tp_ice->pool) {
-	pj_pool_t *pool = tp_ice->pool;
-	tp_ice->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&tp_ice->pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c	(revision 5533)
+++ /pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c	(revision 5534)
@@ -1805,9 +1805,5 @@
 #endif
 
-    if (stream->own_pool) {
-	pj_pool_t *pool = stream->own_pool;
-	stream->own_pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&stream->own_pool);
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjnath/src/pjnath-test/ice_test.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath-test/ice_test.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath-test/ice_test.c	(revision 5534)
@@ -403,9 +403,5 @@
     }
 
-    if (sess->pool) {
-	pj_pool_t *pool = sess->pool;
-	sess->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&sess->pool);
 }
 
Index: /pjproject/trunk/pjnath/src/pjnath-test/server.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath-test/server.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath-test/server.c	(revision 5534)
@@ -255,9 +255,5 @@
     }
 
-    if (test_srv->pool) {
-	pj_pool_t *pool = test_srv->pool;
-	test_srv->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&test_srv->pool);
 }
 
Index: /pjproject/trunk/pjnath/src/pjnath/ice_session.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/ice_session.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath/ice_session.c	(revision 5534)
@@ -462,9 +462,6 @@
     pj_ice_sess *ice = (pj_ice_sess*) obj;
 
-    if (ice->pool) {
-	pj_pool_t *pool = ice->pool;
-	ice->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&ice->pool);
+
     LOG4((THIS_FILE, "ICE session %p destroyed", ice));
 }
Index: /pjproject/trunk/pjnath/src/pjnath/stun_sock.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 5534)
@@ -475,9 +475,5 @@
     */
 
-    if (stun_sock->pool) {
-	pj_pool_t *pool = stun_sock->pool;
-	stun_sock->pool = NULL;
-	pj_pool_release(pool);
-    }
+    pj_pool_safe_release(&stun_sock->pool);
 
     TRACE_(("", "STUN sock %p destroyed", stun_sock));
Index: /pjproject/trunk/pjnath/src/pjnath/turn_session.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/turn_session.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath/turn_session.c	(revision 5534)
@@ -329,10 +329,6 @@
     /* Destroy pool */
     if (sess->pool) {
-	pj_pool_t *pool = sess->pool;
-
 	PJ_LOG(4,(sess->obj_name, "TURN client session destroyed"));
-
-	sess->pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&sess->pool);
     }
 }
Index: /pjproject/trunk/pjnath/src/pjnath/turn_sock.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/turn_sock.c	(revision 5533)
+++ /pjproject/trunk/pjnath/src/pjnath/turn_sock.c	(revision 5534)
@@ -218,8 +218,6 @@
 
     if (turn_sock->pool) {
-	pj_pool_t *pool = turn_sock->pool;
 	PJ_LOG(4,(turn_sock->obj_name, "TURN socket destroyed"));
-	turn_sock->pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&turn_sock->pool);
     }
 }
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 5533)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 5534)
@@ -2011,8 +2011,5 @@
     }
 
-    if (app_config.pool) {
-	pj_pool_release(app_config.pool);
-	app_config.pool = NULL;
-    }
+    pj_pool_safe_release(&app_config.pool);
 
     status = pjsua_destroy();
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 5533)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 5534)
@@ -567,10 +567,6 @@
 
     if (listener->factory.pool) {
-	pj_pool_t *pool = listener->factory.pool;
-
 	PJ_LOG(4,(listener->factory.obj_name,  "SIP TCP transport destroyed"));
-
-	listener->factory.pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&listener->factory.pool);
     }
 }
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c	(revision 5533)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c	(revision 5534)
@@ -604,10 +604,6 @@
 
     if (listener->factory.pool) {
-	pj_pool_t *pool = listener->factory.pool;
-
 	PJ_LOG(4,(listener->factory.obj_name,  "SIP TLS transport destroyed"));
-
-	listener->factory.pool = NULL;
-	pj_pool_release(pool);
+	pj_pool_safe_release(&listener->factory.pool);
     }
 }
