From: Ondřej Surý Date: Tue, 14 Dec 2021 09:40:47 +0000 (+0100) Subject: Don't use mem freelists for isc_mempools X-Git-Tag: v9.16.25~25^2~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=c96b6eb5ece1d44fdfbce45da2364e3764956822;p=thirdparty%2Fbind9.git Don't use mem freelists for isc_mempools Previously, with BIND 9 internal allocator, when isc_mempool_put() would return memory to the allocator, it would not be freed, but it would be returned to the "freelists" and the memory would not be released to the operating system. Change the isc_mempool_get() and isc_mempool_put() to avoid the internal allocator (mem_getunlocked() and mem_putunlocked()). --- diff --git a/lib/isc/mem.c b/lib/isc/mem.c index e51b281458c..564d0eacfe3 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -1817,17 +1817,8 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) { */ MCTXLOCK(mctx); for (i = 0; i < mpctx->fillcount; i++) { - if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { - item = mem_getunlocked(mctx, mpctx->size); - } else { - item = mem_get(mctx, mpctx->size); - if (item != NULL) { - mem_getstats(mctx, mpctx->size); - } - } - if (ISC_UNLIKELY(item == NULL)) { - break; - } + item = mem_get(mctx, mpctx->size); + mem_getstats(mctx, mpctx->size); item->next = mpctx->items; mpctx->items = item; mpctx->freecount++; @@ -1888,12 +1879,8 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) { */ if (mpctx->freecount >= mpctx->freemax) { MCTXLOCK(mctx); - if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { - mem_putunlocked(mctx, mem, mpctx->size); - } else { - mem_putstats(mctx, mem, mpctx->size); - mem_put(mctx, mem, mpctx->size); - } + mem_putstats(mctx, mem, mpctx->size); + mem_put(mctx, mem, mpctx->size); MCTXUNLOCK(mctx); return; }