Re #1686: avoid cache entry destroy in update_res_cache() when it is being used by callback.

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@4553 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Nanang Izzuddin 2013-07-08 01:44:48 +00:00
parent 2f362934d0
commit c0db622eea
1 changed files with 9 additions and 2 deletions

View File

@ -1197,7 +1197,7 @@ 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);
if (cache)
if (cache && --cache->ref_cnt <= 0)
free_entry(resolver, cache);
pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL);
}
@ -1233,7 +1233,7 @@ 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);
if (cache)
if (cache && --cache->ref_cnt <= 0)
free_entry(resolver, cache);
pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL);
return;
@ -1244,6 +1244,13 @@ static void update_res_cache(pj_dns_resolver *resolver,
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 {
/* Reset cache to avoid bloated cache pool */
reset_entry(&cache);