Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 2039)
+++ 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;
