Changeset 5475


Ignore:
Timestamp:
Oct 28, 2016 6:25:03 AM (8 years ago)
Author:
ming
Message:

Re #1974: Remove DNS cache entry from resolver's hash table when app callback has a reference.

Thanks to Richard Mudgett for the patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c

    r5473 r5475  
    14721472        ttl = resolver->settings.cache_max_ttl; 
    14731473 
     1474    /* Get a cache response entry */ 
     1475    cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key, 
     1476                                              sizeof(*key), &hval); 
     1477 
    14741478    /* If TTL is zero, clear the same entry in the hash table */ 
    14751479    if (ttl == 0) { 
    1476         cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key,  
    1477                                                   sizeof(*key), &hval); 
    14781480        /* Remove the entry before releasing its pool (see ticket #1710) */ 
    14791481        pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); 
     
    14851487    } 
    14861488 
    1487     /* Get a cache response entry */ 
    1488     cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key,  
    1489                                               sizeof(*key), &hval); 
    14901489    if (cache == NULL) { 
    1491         cache = alloc_entry(resolver); 
    1492     } else if (cache->ref_cnt > 1) { 
    1493         /* When cache entry is being used by callback (to app), just decrement 
    1494          * ref_cnt so it will be freed after the callback returns and allocate 
    1495          * new entry. 
    1496          */ 
    1497         cache->ref_cnt--; 
    14981490        cache = alloc_entry(resolver); 
    14991491    } else { 
     
    15011493        pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); 
    15021494 
    1503         /* Reset cache to avoid bloated cache pool */ 
    1504         reset_entry(&cache); 
     1495        if (cache->ref_cnt > 1) { 
     1496            /* When cache entry is being used by callback (to app), 
     1497             * just decrement ref_cnt so it will be freed after 
     1498             * the callback returns and allocate new entry. 
     1499             */ 
     1500            cache->ref_cnt--; 
     1501            cache = alloc_entry(resolver); 
     1502        } else { 
     1503            /* Reset cache to avoid bloated cache pool */ 
     1504            reset_entry(&cache); 
     1505        } 
    15051506    } 
    15061507 
Note: See TracChangeset for help on using the changeset viewer.