Index: pjlib-util/src/pjlib-util/resolver.c =================================================================== --- a/pjlib-util/src/pjlib-util/resolver.c (revision 5463) +++ b/pjlib-util/src/pjlib-util/resolver.c (working copy) @@ -1445,10 +1445,12 @@ if (ttl > resolver->settings.cache_max_ttl) ttl = resolver->settings.cache_max_ttl; + /* Get a cache response entry */ + cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key, + sizeof(*key), &hval); + /* If TTL is zero, clear the same entry in the hash table */ if (ttl == 0) { - cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key, - sizeof(*key), &hval); /* Remove the entry before releasing its pool (see ticket #1710) */ pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); @@ -1458,24 +1460,23 @@ return; } - /* Get a cache response entry */ - cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key, - sizeof(*key), &hval); if (cache == NULL) { cache = alloc_entry(resolver); - } else if (cache->ref_cnt > 1) { - /* When cache entry is being used by callback (to app), just decrement - * ref_cnt so it will be freed after the callback returns and allocate - * new entry. - */ - cache->ref_cnt--; - cache = alloc_entry(resolver); } else { /* Remove the entry before resetting its pool (see ticket #1710) */ pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); - /* Reset cache to avoid bloated cache pool */ - reset_entry(&cache); + if (cache->ref_cnt > 1) { + /* When cache entry is being used by callback (to app), just decrement + * ref_cnt so it will be freed after the callback returns and allocate + * new entry. + */ + cache->ref_cnt--; + cache = alloc_entry(resolver); + } else { + /* Reset cache to avoid bloated cache pool */ + reset_entry(&cache); + } } /* Duplicate the packet.