]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
restore isc_mem_setwater() call in the cache
authorEvan Hunt <each@isc.org>
Tue, 31 Oct 2023 11:00:14 +0000 (12:00 +0100)
committerEvan Hunt <each@isc.org>
Wed, 1 Nov 2023 15:18:02 +0000 (15:18 +0000)
Commit 4db150437e14b28c5b50ae466af9ce502fd73185 incorrectly removed the
call to isc_mem_setwater() from dns_cache_setcachesize().  The water()
function is a no-op, but we still need to set high- and low-water marks
in the memory context, otherwise overmem conditions will not be
detected.

lib/dns/cache.c

index f7c3bbef99430ab50613b1c555a5913e49cc875a..ed93b31c8aa157b4064dbddd3f1cf62f2a1225c1 100644 (file)
@@ -239,6 +239,13 @@ dns_cache_getname(dns_cache_t *cache) {
        return (cache->name);
 }
 
+/* This is a no-op, but has to exist for isc_mem_setwater(). */
+static void
+water(void *arg, int mark) {
+       UNUSED(arg);
+       UNUSED(mark);
+}
+
 void
 dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
        REQUIRE(VALID_CACHE(cache));
@@ -254,6 +261,14 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
        LOCK(&cache->lock);
        cache->size = size;
        UNLOCK(&cache->lock);
+
+       size_t hi = size - (size >> 3); /* Approximately 7/8ths. */
+       size_t lo = size - (size >> 2); /* Approximately 3/4ths. */
+       if (size == 0U || hi == 0U || lo == 0U) {
+               isc_mem_clearwater(cache->mctx);
+       } else {
+               isc_mem_setwater(cache->mctx, water, cache, hi, lo);
+       }
 }
 
 size_t