Index: pjproject/trunk/pjlib-util/include/pjlib-util/config.h
===================================================================
--- pjproject/trunk/pjlib-util/include/pjlib-util/config.h	(revision 2123)
+++ pjproject/trunk/pjlib-util/include/pjlib-util/config.h	(revision 2124)
@@ -179,8 +179,8 @@
  * (#pj_dns_packet_dup()) is also capable of performing name compressions.
  *
- * Default: 1000 (as a broad guidance, 400 is good for 4 SRV entries).
+ * Default: 512
  */
 #ifndef PJ_DNS_RESOLVER_RES_BUF_SIZE
-#   define PJ_DNS_RESOLVER_RES_BUF_SIZE		    1000
+#   define PJ_DNS_RESOLVER_RES_BUF_SIZE		    512
 #endif
 
Index: pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
===================================================================
--- pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 2123)
+++ pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 2124)
@@ -151,6 +151,6 @@
     PJ_DECL_LIST_MEMBER(struct cached_res);
 
+    pj_pool_t		    *pool;	    /**< Cache's pool.		    */
     struct res_key	     key;	    /**< Resource key.		    */
-    char		     buf[RES_BUF_SZ];/**< Resource buffer.	    */
     pj_hash_entry_buf	     hbuf;	    /**< Hash buffer		    */
     pj_time_val		     expiry_time;   /**< Expiration time.	    */
@@ -195,7 +195,4 @@
     /* Hash table for cached response */
     pj_hash_table_t	*hrescache;	/**< Cached response in hash table  */
-
-    /* Cached response free list */
-    struct cached_res	 res_free_nodes;
 
     /* Pending asynchronous query, hashed by transaction ID. */
@@ -296,7 +293,6 @@
     }
 
-    /* Response cache hash table and item list */
+    /* Response cache hash table */
     resv->hrescache = pj_hash_create(pool, RES_HASH_TABLE_SIZE);
-    pj_list_init(&resv->res_free_nodes);
 
     /* Query hash table and free list. */
@@ -352,4 +348,5 @@
 					     pj_bool_t notify)
 {
+    pj_hash_iterator_t it_buf, *it;
     PJ_ASSERT_RETURN(resolver, PJ_EINVAL);
 
@@ -358,6 +355,4 @@
 	 * Notify pending queries if requested.
 	 */
-	pj_hash_iterator_t it_buf, *it;
-
 	it = pj_hash_first(resolver->hquerybyid, &it_buf);
 	while (it) {
@@ -378,4 +373,17 @@
     }
 
+    /* Destroy cached entries */
+    it = pj_hash_first(resolver->hrescache, &it_buf);
+    while (it) {
+	struct cached_res *cache;
+
+	cache = (struct cached_res*) pj_hash_this(resolver->hrescache, it);
+	pj_hash_set(NULL, resolver->hrescache, &cache->key, 
+		    sizeof(cache->key), 0, NULL);
+	pj_pool_release(cache->pool);
+
+	it = pj_hash_first(resolver->hrescache, &it_buf);
+    }
+
     if (resolver->own_timer && resolver->timer) {
 	pj_timer_heap_destroy(resolver->timer);
@@ -640,4 +648,26 @@
 
 
+/* Allocate new cache entry */
+static struct cached_res *alloc_entry(pj_dns_resolver *resolver)
+{
+    pj_pool_t *pool;
+    struct cached_res *cache;
+
+    pool = pj_pool_create(resolver->pool->factory, "dnscache",
+			  RES_BUF_SZ, 256, NULL);
+    cache = PJ_POOL_ZALLOC_T(pool, struct cached_res);
+    cache->pool = pool;
+
+    return cache;
+}
+
+/* Put unused/expired cached entry to the free list */
+static void free_entry(pj_dns_resolver *resolver, struct cached_res *cache)
+{
+    PJ_UNUSED_ARG(resolver);
+    pj_pool_release(cache->pool);
+}
+
+
 /*
  * Create and start asynchronous DNS query for a single resource.
@@ -724,5 +754,5 @@
 
 	/* Store the entry into free nodes */
-	pj_list_push_back(&resolver->res_free_nodes, cache);
+	free_entry(resolver, cache);
 
 	/* Must continue with creating a query now */
@@ -1066,7 +1096,5 @@
 {
     struct cached_res *cache;
-    pj_pool_t *res_pool;
     pj_uint32_t hval=0, ttl;
-    PJ_USE_EXCEPTION;
 
     /* If status is unsuccessful, clear the same entry from the cache */
@@ -1075,5 +1103,5 @@
 						  sizeof(*key), &hval);
 	if (cache)
-	    pj_list_push_back(&resolver->res_free_nodes, cache);
+	    free_entry(resolver, cache);
 	pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL);
     }
@@ -1111,5 +1139,5 @@
 						  sizeof(*key), &hval);
 	if (cache)
-	    pj_list_push_back(&resolver->res_free_nodes, cache);
+	    free_entry(resolver, cache);
 	pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL);
 	return;
@@ -1120,10 +1148,5 @@
     					      sizeof(*key), &hval);
     if (cache == NULL) {
-	if (!pj_list_empty(&resolver->res_free_nodes)) {
-	    cache = resolver->res_free_nodes.next;
-	    pj_list_erase(cache);
-	} else {
-	    cache = PJ_POOL_ZALLOC_T(resolver->pool, struct cached_res);
-	}
+	cache = alloc_entry(resolver);
     }
 
@@ -1134,17 +1157,8 @@
      * the name being requested.
      */
-    res_pool = pj_pool_create_on_buf("respool", cache->buf, sizeof(cache->buf));
-    PJ_TRY {
-	cache->pkt = NULL;
-	pj_dns_packet_dup(res_pool, pkt, 
-			  PJ_DNS_NO_NS | PJ_DNS_NO_AR,
-			  &cache->pkt);
-    }
-    PJ_CATCH_ANY {
-	PJ_LOG(1,(THIS_FILE, 
-		  "Not enough memory to duplicate DNS response. Response was "
-		  "truncated."));
-    }
-    PJ_END;
+    cache->pkt = NULL;
+    pj_dns_packet_dup(cache->pool, pkt, 
+		      PJ_DNS_NO_NS | PJ_DNS_NO_AR,
+		      &cache->pkt);
 
     /* Calculate expiration time */
@@ -1163,4 +1177,5 @@
     pj_hash_set_np(resolver->hrescache, &cache->key, sizeof(*key), hval,
 		   cache->hbuf, cache);
+
 }
 
@@ -1253,5 +1268,5 @@
 {
     pj_dns_resolver *resolver;
-    pj_pool_t *pool;
+    pj_pool_t *pool = NULL;
     pj_dns_parsed_packet *dns_pkt;
     pj_dns_async_query *q;
@@ -1383,4 +1398,8 @@
 
 read_next_packet:
+    if (pool) {
+	/* needed just in case PJ_HAS_POOL_ALT_API is set */
+	pj_pool_release(pool);
+    }
     bytes_read = sizeof(resolver->udp_rx_pkt);
     resolver->udp_addr_len = sizeof(resolver->udp_src_addr);
@@ -1516,6 +1535,4 @@
 	}
     }
-    PJ_LOG(3,(resolver->name.ptr, "  Nb. of cached response free nodes: %u",
-	      pj_list_size(&resolver->res_free_nodes)));
     PJ_LOG(3,(resolver->name.ptr, "  Nb. of pending queries: %u (%u)",
 	      pj_hash_count(resolver->hquerybyid),
