From: Mark Andrews Date: Mon, 24 Apr 2017 01:33:30 +0000 (+1000) Subject: 4607. [bug] The memory context's malloced and maxmalloced counters X-Git-Tag: v9.12.0a1~343 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c6ed0fe5fd5b461e050ba0addf2957f25fd8815;p=thirdparty%2Fbind9.git 4607. [bug] The memory context's malloced and maxmalloced counters were being updated without the appropriate lock being held. [RT #44869] --- diff --git a/CHANGES b/CHANGES index ee71cdaee50..d4c501e72f8 100644 --- 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] diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 8e4b3a9677b..e950497daef 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -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; } /*