]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
avoided leakage of a cache entry by adjusting the timing of
authorMark Andrews <marka@isc.org>
Wed, 29 Dec 2004 22:30:10 +0000 (22:30 +0000)
committerMark Andrews <marka@isc.org>
Wed, 29 Dec 2004 22:30:10 +0000 (22:30 +0000)
  incrementing the reference counter to the entry.  Otherwise, the
  entry could leak when dns_acache_setentry() fails.  This must be
  corrected in some way if not by this change. [RT #13339]

lib/dns/acache.c

index 2f4b328da934a2f81af41ab53c4b568bc1510053..42823bf0dc0e38b3f3ce8a524d12056ce9abe697 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: acache.c,v 1.4 2004/12/23 00:13:09 marka Exp $ */
+/* $Id: acache.c,v 1.5 2004/12/29 22:30:10 marka Exp $ */
 
 #include <config.h>
 
@@ -1217,11 +1217,8 @@ dns_acache_createentry(dns_acache_t *acache, dns_db_t *origdb,
                                 isc_result_totext(result));
                return (ISC_R_UNEXPECTED);
        };
-       /*
-        * We need two counters on creation: one for the caller, and one for
-        * the cache object.
-        */
-       isc_refcount_init(&newentry->references, 2);
+
+       isc_refcount_init(&newentry->references, 1);
 
        ISC_LINK_INIT(newentry, link);
        ISC_LINK_INIT(newentry, olink);
@@ -1343,6 +1340,7 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry,
        dbentry_t *odbent;
        dbentry_t *rdbent = NULL;
        isc_boolean_t close_version = ISC_FALSE;
+       dns_acacheentry_t *dummy_entry = NULL;
 
        REQUIRE(DNS_ACACHE_VALID(acache));
        REQUIRE(DNS_ACACHEENTRY_VALID(entry));
@@ -1434,6 +1432,12 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry,
        if (rdbent != NULL)
                ISC_LIST_APPEND(rdbent->referlist, entry, rlink);
 
+       /*
+        * The additional cache needs an implicit reference to entries in its
+        * link.
+        */
+       dns_acache_attachentry(entry, &dummy_entry);
+
        UNLOCK(&entry->lock);
        UNLOCK(&acache->lock);