From 72f6d11aa23b64d1697d1301c459293b964b175d Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Thu, 7 Nov 2013 08:20:30 +0000 Subject: Fix #1710: Modified resolver to always remove cache entry from cache hash table first before releasing/resetting cache pool. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4649 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjlib-util/resolver.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pjlib-util') diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c index 97571612..cdc5d127 100644 --- a/pjlib-util/src/pjlib-util/resolver.c +++ b/pjlib-util/src/pjlib-util/resolver.c @@ -1197,9 +1197,12 @@ static void update_res_cache(pj_dns_resolver *resolver, if (status != PJ_SUCCESS) { 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); + + /* Free the entry */ if (cache && --cache->ref_cnt <= 0) free_entry(resolver, cache); - pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); } @@ -1233,9 +1236,12 @@ static void update_res_cache(pj_dns_resolver *resolver, 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); + + /* Free the entry */ if (cache && --cache->ref_cnt <= 0) free_entry(resolver, cache); - pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); return; } @@ -1252,6 +1258,9 @@ static void update_res_cache(pj_dns_resolver *resolver, 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); } -- cgit v1.2.3