Commit a1cc4108 authored by Mark Andrews's avatar Mark Andrews

avoided leakage of a cache entry by adjusting the timing of

  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]
parent 0c865fa5
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE. * 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> #include <config.h>
...@@ -1217,11 +1217,8 @@ dns_acache_createentry(dns_acache_t *acache, dns_db_t *origdb, ...@@ -1217,11 +1217,8 @@ dns_acache_createentry(dns_acache_t *acache, dns_db_t *origdb,
isc_result_totext(result)); isc_result_totext(result));
return (ISC_R_UNEXPECTED); return (ISC_R_UNEXPECTED);
}; };
/*
* We need two counters on creation: one for the caller, and one for isc_refcount_init(&newentry->references, 1);
* the cache object.
*/
isc_refcount_init(&newentry->references, 2);
ISC_LINK_INIT(newentry, link); ISC_LINK_INIT(newentry, link);
ISC_LINK_INIT(newentry, olink); ISC_LINK_INIT(newentry, olink);
...@@ -1343,6 +1340,7 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry, ...@@ -1343,6 +1340,7 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry,
dbentry_t *odbent; dbentry_t *odbent;
dbentry_t *rdbent = NULL; dbentry_t *rdbent = NULL;
isc_boolean_t close_version = ISC_FALSE; isc_boolean_t close_version = ISC_FALSE;
dns_acacheentry_t *dummy_entry = NULL;
REQUIRE(DNS_ACACHE_VALID(acache)); REQUIRE(DNS_ACACHE_VALID(acache));
REQUIRE(DNS_ACACHEENTRY_VALID(entry)); REQUIRE(DNS_ACACHEENTRY_VALID(entry));
...@@ -1434,6 +1432,12 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry, ...@@ -1434,6 +1432,12 @@ dns_acache_setentry(dns_acache_t *acache, dns_acacheentry_t *entry,
if (rdbent != NULL) if (rdbent != NULL)
ISC_LIST_APPEND(rdbent->referlist, entry, rlink); 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(&entry->lock);
UNLOCK(&acache->lock); UNLOCK(&acache->lock);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment