Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2129)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2130)
@@ -3797,5 +3797,5 @@
 
     /* Create pool for application */
-    app_config.pool = pjsua_pool_create("pjsua", 1000, 1000);
+    app_config.pool = pjsua_pool_create("pjsua-app", 1000, 1000);
 
     /* Initialize default config */
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 2129)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 2130)
@@ -99,4 +99,5 @@
 typedef struct pjsua_acc
 {
+    pj_pool_t	    *pool;	    /**< Pool for this account.		*/
     pjsua_acc_config cfg;	    /**< Account configuration.		*/
     pj_bool_t	     valid;	    /**< Is this account valid?		*/
@@ -156,4 +157,5 @@
 typedef struct pjsua_buddy
 {
+    pj_pool_t		*pool;	    /**< Pool for this buddy.		*/
     unsigned		 index;	    /**< Buddy index.			*/
     pj_str_t		 uri;	    /**< Buddy URI.			*/
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 2129)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 2130)
@@ -109,5 +109,5 @@
 
     name_addr = (pjsip_name_addr*)
-		    pjsip_parse_uri(pjsua_var.pool, acc_cfg->id.ptr,
+		    pjsip_parse_uri(acc->pool, acc_cfg->id.ptr,
 				    acc_cfg->id.slen, 
 				    PJSIP_PARSE_URI_AS_NAMEADDR);
@@ -137,5 +137,5 @@
 	pjsip_uri *reg_uri;
 
-	reg_uri = pjsip_parse_uri(pjsua_var.pool, acc_cfg->reg_uri.ptr,
+	reg_uri = pjsip_parse_uri(acc->pool, acc_cfg->reg_uri.ptr,
 				  acc_cfg->reg_uri.slen, 0);
 	if (reg_uri == NULL) {
@@ -188,8 +188,8 @@
 	pj_str_t tmp;
 
-	pj_strdup_with_null(pjsua_var.pool, &tmp, 
+	pj_strdup_with_null(acc->pool, &tmp, 
 			    &pjsua_var.ua_cfg.outbound_proxy[i]);
 	r = (pjsip_route_hdr*)
-	    pjsip_parse_hdr(pjsua_var.pool, &hname, tmp.ptr, tmp.slen, NULL);
+	    pjsip_parse_hdr(acc->pool, &hname, tmp.ptr, tmp.slen, NULL);
 	if (r == NULL) {
 	    pjsua_perror(THIS_FILE, "Invalid outbound proxy URI",
@@ -205,7 +205,7 @@
 	pj_str_t tmp;
 
-	pj_strdup_with_null(pjsua_var.pool, &tmp, &acc_cfg->proxy[i]);
+	pj_strdup_with_null(acc->pool, &tmp, &acc_cfg->proxy[i]);
 	r = (pjsip_route_hdr*)
-	    pjsip_parse_hdr(pjsua_var.pool, &hname, tmp.ptr, tmp.slen, NULL);
+	    pjsip_parse_hdr(acc->pool, &hname, tmp.ptr, tmp.slen, NULL);
 	if (r == NULL) {
 	    pjsua_perror(THIS_FILE, "Invalid URI in account route set",
@@ -257,4 +257,5 @@
 				   pjsua_acc_id *p_acc_id)
 {
+    pjsua_acc *acc;
     unsigned id;
     pj_status_t status;
@@ -278,6 +279,14 @@
 			{PJSUA_UNLOCK(); return PJ_EBUG;});
 
+    acc = &pjsua_var.acc[id];
+
+    /* Create pool for this account. */
+    if (acc->pool)
+	pj_pool_reset(acc->pool);
+    else
+	acc->pool = pjsua_pool_create("acc%p", 512, 256);
+
     /* Copy config */
-    pjsua_acc_config_dup(pjsua_var.pool, &pjsua_var.acc[id].cfg, cfg);
+    pjsua_acc_config_dup(acc->pool, &pjsua_var.acc[id].cfg, cfg);
     
     /* Normalize registration timeout */
@@ -291,4 +300,6 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Error adding account", status);
+	pj_pool_release(acc->pool);
+	acc->pool = NULL;
 	PJSUA_UNLOCK();
 	return status;
@@ -400,4 +411,10 @@
     pjsua_pres_delete_acc(acc_id);
 
+    /* Release account pool */
+    if (pjsua_var.acc[acc_id].pool) {
+	pj_pool_release(pjsua_var.acc[acc_id].pool);
+	pjsua_var.acc[acc_id].pool = NULL;
+    }
+
     /* Invalidate */
     pjsua_var.acc[acc_id].valid = PJ_FALSE;
@@ -472,6 +489,9 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJSUA_LOCK();
     pjsua_var.acc[acc_id].online_status = is_online;
-    pjrpid_element_dup(pjsua_var.pool, &pjsua_var.acc[acc_id].rpid, pr);
+    pjrpid_element_dup(pjsua_var.acc[acc_id].pool, &pjsua_var.acc[acc_id].rpid, pr);
+    PJSUA_UNLOCK();
+
     pjsua_pres_update_acc(acc_id, PJ_TRUE);
     return PJ_SUCCESS;
@@ -595,5 +615,5 @@
 	    return PJ_FALSE;
 	}
-	pj_strdup2(pjsua_var.pool, &acc->contact, tmp);
+	pj_strdup2(acc->pool, &acc->contact, tmp);
     }
 
@@ -703,6 +723,6 @@
     /* Then append the Service-Route URIs */
     for (i=0; i<uri_cnt; ++i) {
-	hr = pjsip_route_hdr_create(pjsua_var.pool);
-	hr->name_addr.uri = (pjsip_uri*)pjsip_uri_clone(pjsua_var.pool, uri[i]);
+	hr = pjsip_route_hdr_create(acc->pool);
+	hr->name_addr.uri = (pjsip_uri*)pjsip_uri_clone(acc->pool, uri[i]);
 	pj_list_push_back(&acc->route_set, hr);
     }
@@ -983,5 +1003,5 @@
 	}
 
-	pj_strdup_with_null(pjsua_var.pool, &acc->contact, &tmp_contact);
+	pj_strdup_with_null(acc->pool, &acc->contact, &tmp_contact);
     }
 
@@ -1268,14 +1288,16 @@
     pjsip_uri *uri;
     pjsip_sip_uri *sip_uri;
+    pj_pool_t *tmp_pool;
     unsigned i;
 
     PJSUA_LOCK();
 
-    PJ_TODO(dont_use_pjsua_pool);
-
-    pj_strdup_with_null(pjsua_var.pool, &tmp, url);
-
-    uri = pjsip_parse_uri(pjsua_var.pool, tmp.ptr, tmp.slen, 0);
+    tmp_pool = pjsua_pool_create("tmpacc10", 256, 256);
+
+    pj_strdup_with_null(tmp_pool, &tmp, url);
+
+    uri = pjsip_parse_uri(tmp_pool, tmp.ptr, tmp.slen, 0);
     if (!uri) {
+	pj_pool_release(tmp_pool);
 	PJSUA_UNLOCK();
 	return pjsua_var.default_acc;
@@ -1295,9 +1317,11 @@
 	if (i != PJ_ARRAY_SIZE(pjsua_var.acc)) {
 	    /* Found rather matching account */
+	    pj_pool_release(tmp_pool);
 	    PJSUA_UNLOCK();
-	    return 0;
+	    return i;
 	}
 
 	/* Not found, use default account */
+	pj_pool_release(tmp_pool);
 	PJSUA_UNLOCK();
 	return pjsua_var.default_acc;
@@ -1312,4 +1336,5 @@
 	    pjsua_var.acc[acc_id].srv_port == sip_uri->port)
 	{
+	    pj_pool_release(tmp_pool);
 	    PJSUA_UNLOCK();
 	    return acc_id;
@@ -1322,4 +1347,5 @@
 	if (pj_stricmp(&pjsua_var.acc[acc_id].srv_domain, &sip_uri->host)==0)
 	{
+	    pj_pool_release(tmp_pool);
 	    PJSUA_UNLOCK();
 	    return acc_id;
@@ -1329,4 +1355,5 @@
 
     /* Still no match, just use default account */
+    pj_pool_release(tmp_pool);
     PJSUA_UNLOCK();
     return pjsua_var.default_acc;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 2129)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 2130)
@@ -331,4 +331,5 @@
 					  pjsua_call_id *p_call_id)
 {
+    pj_pool_t *tmp_pool;
     pjsip_dialog *dlg = NULL;
     pjmedia_sdp_session *offer;
@@ -383,4 +384,7 @@
     call = &pjsua_var.calls[call_id];
 
+    /* Create temporary pool */
+    tmp_pool = pjsua_pool_create("tmpcall10", 512, 256);
+
     /* Verify that destination URI is valid before calling 
      * pjsua_acc_create_uac_contact, or otherwise there  
@@ -389,22 +393,14 @@
      */
     if (1) {
-	pj_pool_t *pool;
 	pjsip_uri *uri;
 	pj_str_t dup;
 
-	pool = pjsua_pool_create("tmp-uri", 4000, 4000);
-	if (!pool) {
-	    pjsua_perror(THIS_FILE, "Unable to create pool", PJ_ENOMEM);
-	    PJSUA_UNLOCK();
-	    return PJ_ENOMEM;
-	}
-	
-	pj_strdup_with_null(pool, &dup, dest_uri);
-	uri = pjsip_parse_uri(pool, dup.ptr, dup.slen, 0);
-	pj_pool_release(pool);
+	pj_strdup_with_null(tmp_pool, &dup, dest_uri);
+	uri = pjsip_parse_uri(tmp_pool, dup.ptr, dup.slen, 0);
 
 	if (uri == NULL) {
 	    pjsua_perror(THIS_FILE, "Unable to make call", 
 			 PJSIP_EINVALIDREQURI);
+	    pj_pool_release(tmp_pool);
 	    PJSUA_UNLOCK();
 	    return PJSIP_EINVALIDREQURI;
@@ -427,9 +423,10 @@
 	contact = acc->contact;
     } else {
-	status = pjsua_acc_create_uac_contact(pjsua_var.pool, &contact,
+	status = pjsua_acc_create_uac_contact(tmp_pool, &contact,
 					      acc_id, dest_uri);
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
 			 status);
+	    pj_pool_release(tmp_pool);
 	    PJSUA_UNLOCK();
 	    return status;
@@ -443,4 +440,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Dialog creation failed", status);
+	pj_pool_release(tmp_pool);
 	PJSUA_UNLOCK();
 	return status;
@@ -550,4 +548,5 @@
 	*p_call_id = call_id;
 
+    pj_pool_release(tmp_pool);
     PJSUA_UNLOCK();
 
@@ -567,4 +566,5 @@
     }
 
+    pj_pool_release(tmp_pool);
     PJSUA_UNLOCK();
     return status;
@@ -2618,4 +2618,5 @@
 {
     pj_status_t status;
+    pj_pool_t *pool;
     pjmedia_sdp_conn *conn;
     pjmedia_sdp_attr *attr;
@@ -2623,4 +2624,7 @@
     pjmedia_sdp_session *sdp;
 
+    /* Use call's pool */
+    pool = call->inv->pool;
+
     /* Get media socket info */
     pjmedia_transport_info_init(&tp_info);
@@ -2628,5 +2632,5 @@
 
     /* Create new offer */
-    status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pjsua_var.pool, 1,
+    status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, 1,
 				      &tp_info.sock_info, &sdp);
     if (status != PJ_SUCCESS) {
@@ -2650,5 +2654,5 @@
 
     /* Add inactive attribute */
-    attr = pjmedia_sdp_attr_create(pjsua_var.pool, "inactive", NULL);
+    attr = pjmedia_sdp_attr_create(pool, "inactive", NULL);
     pjmedia_sdp_media_add_attr(sdp->media[0], attr);
 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 2129)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 2130)
@@ -581,5 +581,5 @@
 
     /* Create memory pool for application. */
-    pjsua_var.pool = pjsua_pool_create("pjsua", 4000, 4000);
+    pjsua_var.pool = pjsua_pool_create("pjsua", 1000, 1000);
     
     PJ_ASSERT_RETURN(pjsua_var.pool, PJ_ENOMEM);
@@ -1070,5 +1070,13 @@
 	pjsua_pres_shutdown();
 
-	/* Unregister, if required: */
+	/* Destroy pool in the buddy object */
+	for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.buddy); ++i) {
+	    if (pjsua_var.buddy[i].pool) {
+		pj_pool_release(pjsua_var.buddy[i].pool);
+		pjsua_var.buddy[i].pool = NULL;
+	    }
+	}
+
+	/* Destroy accounts */
 	for (i=0; i<(int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) {
 	    if (!pjsua_var.acc[i].valid)
@@ -1077,4 +1085,9 @@
 	    if (pjsua_var.acc[i].regc) {
 		pjsua_acc_set_registration(i, PJ_FALSE);
+	    }
+
+	    if (pjsua_var.acc[i].pool) {
+		pj_pool_release(pjsua_var.acc[i].pool);
+		pjsua_var.acc[i].pool = NULL;
 	    }
 	}
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 2129)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 2130)
@@ -174,5 +174,7 @@
 static void reset_buddy(pjsua_buddy_id id)
 {
+    pj_pool_t *pool = pjsua_var.buddy[id].pool;
     pj_bzero(&pjsua_var.buddy[id], sizeof(pjsua_var.buddy[id]));
+    pjsua_var.buddy[id].pool = pool;
     pjsua_var.buddy[id].index = id;
 }
@@ -186,4 +188,5 @@
 {
     pjsip_name_addr *url;
+    pjsua_buddy *buddy;
     pjsip_sip_uri *sip_uri;
     int index;
@@ -210,12 +213,24 @@
     }
 
+    buddy = &pjsua_var.buddy[index];
+
+    /* Create pool for this buddy */
+    if (buddy->pool) {
+	pj_pool_reset(buddy->pool);
+    } else {
+	char name[PJ_MAX_OBJ_NAME];
+	pj_ansi_snprintf(name, sizeof(name), "buddy%03d", index);
+	buddy->pool = pjsua_pool_create(name, 512, 256);
+    }
 
     /* Get name and display name for buddy */
-    pj_strdup_with_null(pjsua_var.pool, &tmp, &cfg->uri);
-    url = (pjsip_name_addr*)pjsip_parse_uri(pjsua_var.pool, tmp.ptr, tmp.slen,
+    pj_strdup_with_null(buddy->pool, &tmp, &cfg->uri);
+    url = (pjsip_name_addr*)pjsip_parse_uri(buddy->pool, tmp.ptr, tmp.slen,
 					    PJSIP_PARSE_URI_AS_NAMEADDR);
 
     if (url == NULL) {
 	pjsua_perror(THIS_FILE, "Unable to add buddy", PJSIP_EINVALIDURI);
+	pj_pool_release(buddy->pool);
+	buddy->pool = NULL;
 	PJSUA_UNLOCK();
 	return PJSIP_EINVALIDURI;
@@ -223,6 +238,10 @@
 
     /* Only support SIP schemes */
-    if (!PJSIP_URI_SCHEME_IS_SIP(url) && !PJSIP_URI_SCHEME_IS_SIPS(url))
+    if (!PJSIP_URI_SCHEME_IS_SIP(url) && !PJSIP_URI_SCHEME_IS_SIPS(url)) {
+	pj_pool_release(buddy->pool);
+	buddy->pool = NULL;
+	PJSUA_UNLOCK();
 	return PJSIP_EINVALIDSCHEME;
+    }
 
     /* Reset buddy, to make sure everything is cleared with default
@@ -1050,5 +1069,5 @@
 
     buddy->contact.ptr = (char*)
-			 pj_pool_alloc(pjsua_var.pool, PJSIP_MAX_URL_SIZE);
+			 pj_pool_alloc(buddy->pool, PJSIP_MAX_URL_SIZE);
     buddy->contact.slen = pjsip_uri_print( PJSIP_URI_IN_CONTACT_HDR,
 					   contact_hdr->uri,
@@ -1117,4 +1136,5 @@
 static void subscribe_buddy_presence(unsigned index)
 {
+    pj_pool_t *tmp_pool = NULL;
     pjsua_buddy *buddy;
     int acc_id;
@@ -1138,9 +1158,12 @@
 	contact = acc->contact;
     } else {
-	status = pjsua_acc_create_uac_contact(pjsua_var.pool, &contact,
+	tmp_pool = pjsua_pool_create("tmpbuddy", 512, 256);
+
+	status = pjsua_acc_create_uac_contact(tmp_pool, &contact,
 					      acc_id, &buddy->uri);
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
 		         status);
+	    pj_pool_release(tmp_pool);
 	    return;
 	}
@@ -1156,4 +1179,5 @@
 	pjsua_perror(THIS_FILE, "Unable to create dialog", 
 		     status);
+	if (tmp_pool) pj_pool_release(tmp_pool);
 	return;
     }
@@ -1166,4 +1190,5 @@
 		     status);
 	pjsip_dlg_terminate(buddy->dlg);
+	if (tmp_pool) pj_pool_release(tmp_pool);
 	return;
     }
@@ -1203,4 +1228,5 @@
 	pjsua_perror(THIS_FILE, "Unable to create initial SUBSCRIBE", 
 		     status);
+	if (tmp_pool) pj_pool_release(tmp_pool);
 	return;
     }
@@ -1216,6 +1242,9 @@
 	pjsua_perror(THIS_FILE, "Unable to send initial SUBSCRIBE", 
 		     status);
+	if (tmp_pool) pj_pool_release(tmp_pool);
 	return;
     }
+
+    if (tmp_pool) pj_pool_release(tmp_pool);
 }
 
