]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4607. [bug] The memory context's malloced and maxmalloced counters
authorMark Andrews <marka@isc.org>
Mon, 24 Apr 2017 01:33:30 +0000 (11:33 +1000)
committerMark Andrews <marka@isc.org>
Mon, 24 Apr 2017 01:33:30 +0000 (11:33 +1000)
                        were being updated without the appropriate lock being
                        held.  [RT #44869]

CHANGES
lib/isc/mem.c

diff --git a/CHANGES b/CHANGES
index ee71cdaee5001a7df00e00aeac6c0d6a0e2f8f07..d4c501e72f8687657df63314a78ec127b84a03fb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+4607.  [bug]           The memory context's malloced and maxmalloced counters
+                       were being updated without the appropriate lock being
+                       held.  [RT #44869]
+
 4606.  [port]          Stop using experimental "Experimental keys on scalar"
                        feature of perl as it has been removed. [RT #45012]
 
index 8e4b3a9677b7941752646f894ee1d0919ef5759d..e950497daef34b62de38aca90213eb8a581d932d 100644 (file)
@@ -810,11 +810,6 @@ mem_get(isc__mem_t *ctx, size_t size) {
                ret[size-1] = 0xbe;
 #  endif
 #endif
-       if (ret != NULL) {
-               ctx->malloced += size;
-               if (ctx->malloced > ctx->maxmalloced)
-                       ctx->maxmalloced = ctx->malloced;
-       }
 
        return (ret);
 }
@@ -827,15 +822,12 @@ static inline void
 mem_put(isc__mem_t *ctx, void *mem, size_t size) {
 #if ISC_MEM_CHECKOVERRUN
        INSIST(((unsigned char *)mem)[size] == 0xbe);
+       size += 1;
 #endif
 #if ISC_MEM_FILL
        memset(mem, 0xde, size); /* Mnemonic for "dead". */
 #endif
        (ctx->memfree)(ctx->arg, mem);
-#if ISC_MEM_CHECKOVERRUN
-       size += 1;
-#endif
-       ctx->malloced -= size;
 }
 
 /*!
@@ -853,6 +845,13 @@ mem_getstats(isc__mem_t *ctx, size_t size) {
                ctx->stats[size].gets++;
                ctx->stats[size].totalgets++;
        }
+
+#if ISC_MEM_CHECKOVERRUN
+       size += 1;
+#endif
+       ctx->malloced += size;
+       if (ctx->malloced > ctx->maxmalloced)
+               ctx->maxmalloced = ctx->malloced;
 }
 
 /*!
@@ -872,6 +871,10 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
                INSIST(ctx->stats[size].gets > 0U);
                ctx->stats[size].gets--;
        }
+#if ISC_MEM_CHECKOVERRUN
+       size += 1;
+#endif
+       ctx->malloced -= size;
 }
 
 /*