diff --git a/lib/dns/include/dns/rbt.h b/lib/dns/include/dns/rbt.h index 3b62e12114..c144f83b49 100644 --- a/lib/dns/include/dns/rbt.h +++ b/lib/dns/include/dns/rbt.h @@ -992,4 +992,11 @@ dns__rbtnode_namelen(dns_rbtnode_t *node); * Returns the length of the full name of the node. Used only internally * and in unit tests. */ + +unsigned int +dns__rbtnode_getsize(dns_rbtnode_t *node); +/* + * Return allocated size for a node. + */ + ISC_LANG_ENDDECLS diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index 57dcd54542..4d8c142fc2 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -302,6 +302,13 @@ dns__rbtnode_namelen(dns_rbtnode_t *node) { return (len); } +unsigned int +dns__rbtnode_getsize(dns_rbtnode_t *node) { + REQUIRE(DNS_RBTNODE_VALID(node)); + + return (NODE_SIZE(node)); +} + /* * Initialize a red/black tree of trees. */ diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 55776d5a74..864a159097 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -10201,7 +10201,9 @@ overmem_purge(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader, bool tree_locked) { uint32_t locknum_start = rbtdb->lru_sweep++ % rbtdb->node_lock_count; uint32_t locknum = locknum_start; - size_t purgesize = rdataset_size(newheader); + /* Size of added data, possible node and possible ENT node. */ + size_t purgesize = rdataset_size(newheader) + + 2 * dns__rbtnode_getsize(newheader->node); size_t purged = 0; isc_stdtime_t min_last_used = 0; size_t max_passes = 8;