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:
parent
2f362934d0
commit
c0db622eea
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue