Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 4579)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 4580)
@@ -1280,4 +1280,5 @@
     pjsua_transport_config tcp_cfg;
     unsigned i;
+    pj_pool_t *tmp_pool;
     pj_status_t status;
 
@@ -1289,4 +1290,5 @@
     /* Create pool for application */
     app_config.pool = pjsua_pool_create("pjsua-app", 1000, 1000);
+    tmp_pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);;
 
     /* Init CLI & its FE settings */
@@ -1300,6 +1302,8 @@
     /** Parse args **/
     status = load_config(app_cfg.argc, app_cfg.argv, &uri_arg);
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	pj_pool_release(tmp_pool);
 	return status;
+    }
 
     /* Initialize application callbacks */
@@ -1340,6 +1344,8 @@
     status = pjsua_init(&app_config.cfg, &app_config.log_cfg,
 			&app_config.media_cfg);
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	pj_pool_release(tmp_pool);
 	return status;
+    }
 
     /* Initialize our module to handle otherwise unhandled request */
@@ -1588,5 +1594,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(aid, &acc_cfg);
+	    pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    pjsua_acc_modify(aid, &acc_cfg);
@@ -1627,5 +1633,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(aid, &acc_cfg);
+	    pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    if (app_config.ipv6)
@@ -1661,5 +1667,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(aid, &acc_cfg);
+	    pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    pjsua_acc_modify(aid, &acc_cfg);
@@ -1686,5 +1692,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(aid, &acc_cfg);
+	    pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    if (app_config.ipv6)
@@ -1721,5 +1727,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(acc_id, &acc_cfg);
+	    pjsua_acc_get_config(acc_id, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    pjsua_acc_modify(acc_id, &acc_cfg);
@@ -1745,5 +1751,5 @@
 	if (PJMEDIA_HAS_VIDEO) {
 	    pjsua_acc_config acc_cfg;
-	    pjsua_acc_get_config(aid, &acc_cfg);
+	    pjsua_acc_get_config(aid, tmp_pool, &acc_cfg);
 	    app_config_init_video(&acc_cfg);
 	    if (app_config.ipv6)
@@ -1830,7 +1836,9 @@
     call_opt.vid_cnt = app_config.vid.vid_cnt;
 
+    pj_pool_release(tmp_pool);
     return PJ_SUCCESS;
 
 on_error:
+    pj_pool_release(tmp_pool);
     app_destroy();
     return status;
Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_cli.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_cli.c	(revision 4579)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_cli.c	(revision 4580)
@@ -2109,7 +2109,9 @@
 {
     pjsua_acc_config acc_cfg;
+    pj_pool_t *pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);
     
-    pjsua_acc_get_config(current_acc, &acc_cfg);
+    pjsua_acc_get_config(current_acc, pool, &acc_cfg);
     app_config_show_video(current_acc, &acc_cfg);
+    pj_pool_release(pool);
     return PJ_SUCCESS;
 }
@@ -2119,8 +2121,9 @@
     pjsua_acc_config acc_cfg;
     pj_cli_cmd_id cmd_id = pj_cli_get_cmd_id(cval->cmd);
+    pj_pool_t *pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);
 
     CHECK_PJSUA_RUNNING();
 
-    pjsua_acc_get_config(current_acc, &acc_cfg);
+    pjsua_acc_get_config(current_acc, pool, &acc_cfg);
 
     switch(cmd_id) {
@@ -2149,4 +2152,5 @@
     }
     modify_video_account(&acc_cfg);
+    pj_pool_release(pool);
     return PJ_SUCCESS;
 }
Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_legacy.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_legacy.c	(revision 4579)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_legacy.c	(revision 4580)
@@ -313,6 +313,7 @@
 	pjsua_acc_config acc_cfg;
 	pj_bool_t changed = PJ_FALSE;
-
-	pjsua_acc_get_config(current_acc, &acc_cfg);
+	pj_pool_t *tmp_pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);
+
+	pjsua_acc_get_config(current_acc, tmp_pool, &acc_cfg);
 
 	if (argc == 3 && strcmp(argv[2], "show")==0) {
@@ -335,4 +336,5 @@
 	    changed = PJ_TRUE;
 	} else {
+	    pj_pool_release(tmp_pool);
 	    goto on_error;
 	}
@@ -344,4 +346,5 @@
 			     current_acc));
 	}
+	pj_pool_release(tmp_pool);
 
     } else if (strcmp(argv[1], "call")==0) {
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4579)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 4580)
@@ -3590,4 +3590,5 @@
  *
  * @param acc_id	The account ID.
+ * @param pool		Pool to duplicate the config.
  * @param acc_cfg	Structure to receive the settings.
  *
@@ -3595,4 +3596,5 @@
  */
 PJ_DECL(pj_status_t) pjsua_acc_get_config(pjsua_acc_id acc_id,
+                                          pj_pool_t *pool,
                                           pjsua_acc_config *acc_cfg);
 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4579)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 4580)
@@ -686,10 +686,76 @@
 /* Get config */
 PJ_DEF(pj_status_t) pjsua_acc_get_config(pjsua_acc_id acc_id,
+                                         pj_pool_t *pool,
                                          pjsua_acc_config *acc_cfg)
 {
     PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc)
                      && pjsua_var.acc[acc_id].valid, PJ_EINVAL);
-    pj_memcpy(acc_cfg, &pjsua_var.acc[acc_id].cfg, sizeof(*acc_cfg));
+    //this now would not work due to corrupt header list
+    //pj_memcpy(acc_cfg, &pjsua_var.acc[acc_id].cfg, sizeof(*acc_cfg));
+    pjsua_acc_config_dup(pool, acc_cfg, &pjsua_var.acc[acc_id].cfg);
     return PJ_SUCCESS;
+}
+
+/* Compare two SIP headers. Return zero if equal */
+static int pjsip_hdr_cmp(const pjsip_hdr *h1, const pjsip_hdr *h2)
+{
+    char buf1[PJSIP_MAX_URL_SIZE];
+    char buf2[PJSIP_MAX_URL_SIZE];
+    pj_str_t p1, p2;
+
+    p1.ptr = buf1;
+    p1.slen = 0;
+    p2.ptr = buf2;
+    p2.slen = 0;
+
+    p1.slen = pjsip_hdr_print_on((void*)h1, buf1, sizeof(buf1));
+    if (p1.slen < 0)
+	p1.slen = 0;
+    p2.slen = pjsip_hdr_print_on((void*)h2, buf2, sizeof(buf2));
+    if (p2.slen < 0)
+	p2.slen = 0;
+
+    return pj_strcmp(&p1, &p2);
+}
+
+/* Update SIP header list from another list. Return PJ_TRUE if
+ * the list has been updated */
+static pj_bool_t update_hdr_list(pj_pool_t *pool, pjsip_hdr *dst,
+                                 const pjsip_hdr *src)
+{
+    pjsip_hdr *dst_i;
+    const pjsip_hdr *src_i;
+    pj_bool_t changed = PJ_FALSE;
+
+    /* Remove header that's no longer needed */
+    for (dst_i = dst->next; dst_i != dst; ) {
+	for (src_i = src->next; src_i != src; src_i = src_i->next) {
+	    if (pjsip_hdr_cmp(dst_i, src_i) == 0)
+		break;
+	}
+	if (src_i == src) {
+	    pjsip_hdr *next = dst_i->next;
+	    pj_list_erase(dst_i);
+	    changed = PJ_TRUE;
+	    dst_i = next;
+	} else {
+	    dst_i = dst_i->next;
+	}
+    }
+
+    /* Add new header */
+    for (src_i = src->next; src_i != src; src_i = src_i->next) {
+	for (dst_i = dst->next; dst_i != dst; dst_i = dst_i->next) {
+	    if (pjsip_hdr_cmp(dst_i, src_i) == 0)
+		break;
+	}
+	if (dst_i == dst) {
+	    dst_i = pjsip_hdr_clone(pool, src_i);
+	    pj_list_push_back(dst, dst_i);
+	    changed = PJ_TRUE;
+	}
+    }
+
+    return changed;
 }
 
@@ -778,4 +844,13 @@
 	reg_sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(reg_uri);
     }
+
+    /* REGISTER header list */
+    if (update_hdr_list(acc->pool, &acc->cfg.reg_hdr_list, &cfg->reg_hdr_list)) {
+	update_reg = PJ_TRUE;
+	unreg_first = PJ_TRUE;
+    }
+
+    /* SUBSCRIBE header list */
+    update_hdr_list(acc->pool, &acc->cfg.sub_hdr_list, &cfg->sub_hdr_list);
 
     /* Global outbound proxy */
