From aa23a35d81a9618a40c4a9b44be48009553e4777 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 8 Feb 2001 23:30:32 +0000 Subject: [PATCH] 733. [bug] Reference counts of dns_acl_t objects need to be locked but were not. [RT #801] --- CHANGES | 4 ++++ lib/dns/acl.c | 14 +++++++------- lib/dns/include/dns/acl.h | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 863c5b61f5..f89272006a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ + + 733. [bug] Reference counts of dns_acl_t objects need to be + locked but were not. [RT #801] + 732. [bug] Glue with 0 TTL could also cause SERVFAIL. [RT #828] 731. [bug] Certain zone errors could cause named-checkzone to diff --git a/lib/dns/acl.c b/lib/dns/acl.c index 3c3ed47c62..6628f39a27 100644 --- a/lib/dns/acl.c +++ b/lib/dns/acl.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: acl.c,v 1.20 2001/01/17 17:44:49 gson Exp $ */ +/* $Id: acl.c,v 1.21 2001/02/08 23:30:31 gson Exp $ */ #include @@ -41,7 +41,7 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) { return (ISC_R_NOMEMORY); acl->mctx = mctx; acl->name = NULL; - acl->refcount = 1; + isc_refcount_init(&acl->refcount, 1); acl->elements = NULL; acl->alloc = 0; acl->length = 0; @@ -235,8 +235,7 @@ dns_aclelement_match(isc_netaddr_t *reqaddr, void dns_acl_attach(dns_acl_t *source, dns_acl_t **target) { REQUIRE(DNS_ACL_VALID(source)); - INSIST(source->refcount > 0); - source->refcount++; + isc_refcount_increment(&source->refcount, NULL); *target = source; } @@ -261,6 +260,7 @@ destroy(dns_acl_t *dacl) { dacl->alloc * sizeof(dns_aclelement_t)); if (dacl->name != NULL) isc_mem_free(dacl->mctx, dacl->name); + isc_refcount_destroy(&dacl->refcount); dacl->magic = 0; isc_mem_put(dacl->mctx, dacl, sizeof(*dacl)); } @@ -268,10 +268,10 @@ destroy(dns_acl_t *dacl) { void dns_acl_detach(dns_acl_t **aclp) { dns_acl_t *acl = *aclp; + unsigned int refs; REQUIRE(DNS_ACL_VALID(acl)); - INSIST(acl->refcount > 0); - acl->refcount--; - if (acl->refcount == 0) + isc_refcount_decrement(&acl->refcount, &refs); + if (refs == 0) destroy(acl); *aclp = NULL; } diff --git a/lib/dns/include/dns/acl.h b/lib/dns/include/dns/acl.h index d952d025bb..f40cf10c7a 100644 --- a/lib/dns/include/dns/acl.h +++ b/lib/dns/include/dns/acl.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: acl.h,v 1.17 2001/01/09 21:52:15 bwelling Exp $ */ +/* $Id: acl.h,v 1.18 2001/02/08 23:30:32 gson Exp $ */ #ifndef DNS_ACL_H #define DNS_ACL_H 1 @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -72,7 +73,7 @@ struct dns_aclelement { struct dns_acl { isc_uint32_t magic; isc_mem_t *mctx; - unsigned int refcount; + isc_refcount_t refcount; dns_aclelement_t *elements; unsigned int alloc; /* Elements allocated */ unsigned int length; /* Elements initialized */