summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2016-10-28 06:25:03 +0000
committerLiong Sauw Ming <ming@teluu.com>2016-10-28 06:25:03 +0000
commitd9e2627c11f50e06103bbec466c22bee317a299c (patch)
treeef788f19543713e83f48e47bdfb353f4b825713e
parent62469d7d94fc19619d7fef8b07d284624c8e997e (diff)
Re #1974: Remove DNS cache entry from resolver's hash table when app callback has a reference.
Thanks to Richard Mudgett for the patch. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5475 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib-util/src/pjlib-util/resolver.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c
index 6dba6e25..cfca16ad 100644
--- a/pjlib-util/src/pjlib-util/resolver.c
+++ b/pjlib-util/src/pjlib-util/resolver.c
@@ -1471,10 +1471,12 @@ static void update_res_cache(pj_dns_resolver *resolver,
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);
@@ -1484,24 +1486,23 @@ static void update_res_cache(pj_dns_resolver *resolver,
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.