diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2013-07-08 01:44:48 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2013-07-08 01:44:48 +0000 |
commit | 753074502fc69345d693068f13f1f1b58de70222 (patch) | |
tree | c470481583ca017082c54709d2cbca870de21c4e /pjlib-util | |
parent | 5fd3cdd741c91142c08b280ff9219f29dccc817d (diff) |
Re #1686: avoid cache entry destroy in update_res_cache() when it is being used by callback.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4553 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util')
-rw-r--r-- | pjlib-util/src/pjlib-util/resolver.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c index 606b8584..97571612 100644 --- a/pjlib-util/src/pjlib-util/resolver.c +++ b/pjlib-util/src/pjlib-util/resolver.c @@ -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); |