From: Ondřej Surý Date: Thu, 18 Jun 2026 15:15:32 +0000 (+0200) Subject: Free the slabheader proofs in its destructor X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=202889b044db24d9ff0247daa6011249cc9b6ed5;p=thirdparty%2Fbind9.git Free the slabheader proofs in its destructor Now that the slabheader carries its own memory context, free its noqname/closest proofs from slabheader_destroy rather than reaching through the owning node's deletedata method. That was the method's last caller, so remove dns_db_deletedata entirely; the cache bookkeeping it performed (rrset statistics and the dirty list) becomes a plain helper called wherever a header leaves the cache. --- diff --git a/lib/dns/db.c b/lib/dns/db.c index 01e0f75219..cb97364d6a 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -1070,14 +1070,6 @@ dns_db_expiredata(dns_dbnode_t *node, void *data) { } } -void -dns_db_deletedata(dns_dbnode_t *node, void *data) { - REQUIRE(node != NULL && node->methods != NULL); - if (node->methods->deletedata != NULL) { - (node->methods->deletedata)(node, data); - } -} - void dns_db_setmaxrrperset(dns_db_t *db, uint32_t value) { REQUIRE(DNS_DB_VALID(db)); diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index 90cd159a3b..baf9486ba1 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -80,7 +80,6 @@ typedef struct dns_dbnode_methods { dns_dbnode_t **targetp DNS__DB_FLARG); void (*detachnode)(dns_dbnode_t **targetp DNS__DB_FLARG); - void (*deletedata)(dns_dbnode_t *node, void *data); void (*expiredata)(dns_dbnode_t *node, void *data); } dns_dbnode_methods_t; @@ -1772,14 +1771,6 @@ dns_db_expiredata(dns_dbnode_t *node, void *data); * node 'node' as expired. */ -void -dns_db_deletedata(dns_dbnode_t *node, void *data); -/*%< - * Tell the database to prepare to delete the block of data 'data' - * stored at node 'node. This may include, for example, removing the - * data from an LRU list or a heap. - */ - void dns_db_setmaxrrperset(dns_db_t *db, uint32_t value); /*%< diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index 3528a1e39b..a5f50deff7 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -265,14 +265,11 @@ qpcnode_attachnode(dns_dbnode_t *source, dns_dbnode_t **targetp DNS__DB_FLARG); static void qpcnode_detachnode(dns_dbnode_t **nodep DNS__DB_FLARG); static void -qpcnode_deletedata(dns_dbnode_t *node, void *data); -static void qpcnode_expiredata(dns_dbnode_t *node, void *data); static dns_dbnode_methods_t qpcnode_methods = (dns_dbnode_methods_t){ .attachnode = qpcnode_attachnode, .detachnode = qpcnode_detachnode, - .deletedata = qpcnode_deletedata, .expiredata = qpcnode_expiredata, }; @@ -527,6 +524,9 @@ qpcache_hit(qpcache_t *qpdb ISC_ATTR_UNUSED, dns_slabheader_t *header) { * DB Routines */ +static void +header_cleanup(dns_dbnode_t *node ISC_ATTR_UNUSED, void *data); + static void clean_cache_headers(dns_slabtop_t *top) { dns_slabheader_t *parent = first_header(top); @@ -537,7 +537,7 @@ clean_cache_headers(dns_slabtop_t *top) { dns_slabheader_t *header = next_header(parent), *header_next = NULL; cds_list_for_each_entry_safe_from(header, header_next, &top->headers, headers_link) { - cds_list_del(&header->headers_link); + header_cleanup(header->node, header); dns_slabheader_detach(&header); } } @@ -573,7 +573,7 @@ clean_cache_node(qpcache_t *qpdb, qpcnode_t *node) { if (!EXISTS(header) || ANCIENT(header) || (STALE(header) && !KEEPSTALE(qpdb))) { - cds_list_del(&header->headers_link); + header_cleanup(header->node, header); dns_slabheader_detach(&header); } @@ -2819,11 +2819,11 @@ qpcache_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, DNS_SLABHEADER_SETATTR(newheader, DNS_SLABHEADERATTR_OPTOUT); } if (rdataset->attributes.noqname) { - CHECK(addnoqname(qpnode->mctx, newheader, qpdb->maxrrperset, + CHECK(addnoqname(newheader->mctx, newheader, qpdb->maxrrperset, rdataset)); } if (rdataset->attributes.closest) { - CHECK(addclosest(qpnode->mctx, newheader, qpdb->maxrrperset, + CHECK(addclosest(newheader->mctx, newheader, qpdb->maxrrperset, rdataset)); } @@ -3453,10 +3453,12 @@ dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) { } static void -qpcnode_deletedata(dns_dbnode_t *node ISC_ATTR_UNUSED, void *data) { +header_cleanup(dns_dbnode_t *node ISC_ATTR_UNUSED, void *data) { dns_slabheader_t *header = data; qpcache_t *qpdb = HEADERNODE(header)->qpdb; + cds_list_del(&header->headers_link); + if (ISC_LINK_LINKED(header, dirtylink)) { ISC_LIST_UNLINK(HEADERNODE(header)->dirty, header, dirtylink); } @@ -3466,13 +3468,6 @@ qpcnode_deletedata(dns_dbnode_t *node ISC_ATTR_UNUSED, void *data) { */ update_rrsetstats(qpdb->rrsetstats, header->typepair, atomic_load_acquire(&header->attributes), false); - - if (header->noqname != NULL) { - dns_slabheader_freeproof(qpdb->common.mctx, &header->noqname); - } - if (header->closest != NULL) { - dns_slabheader_freeproof(qpdb->common.mctx, &header->closest); - } } static void @@ -3522,7 +3517,7 @@ qpcnode_destroy(qpcnode_t *qpnode) { cds_list_for_each_entry_safe(header, header_next, &top->headers, headers_link) { - cds_list_del(&header->headers_link); + header_cleanup(header->node, header); dns_slabheader_detach(&header); } diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c index 7753f609d6..bb6998ac61 100644 --- a/lib/dns/rdataslab.c +++ b/lib/dns/rdataslab.c @@ -572,14 +572,19 @@ static void slabheader_destroy(dns_slabheader_t *header) { unsigned int size; - dns_db_deletedata(header->node, header); - if (EXISTS(header)) { size = dns_rdataslab_size(header); } else { size = sizeof(*header); } + if (header->noqname != NULL) { + dns_slabheader_freeproof(header->mctx, &header->noqname); + } + if (header->closest != NULL) { + dns_slabheader_freeproof(header->mctx, &header->closest); + } + isc_mem_putanddetach(&header->mctx, header, size); }