From: Mark Andrews Date: Tue, 14 Aug 2018 07:13:20 +0000 (+1000) Subject: mempool didn't work for sizes less than sizeof(void*) X-Git-Tag: v9.13.3~63^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5dd1beec8eb73690ade0da70144e1d64693aac18;p=thirdparty%2Fbind9.git mempool didn't work for sizes less than sizeof(void*) --- diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 766302d1e09..aa3b900d6cc 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -1841,6 +1841,12 @@ isc__mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) { mpctx->common.magic = ISCAPI_MPOOL_MAGIC; mpctx->lock = NULL; mpctx->mctx = mctx; + /* + * Mempools are stored as a linked list of element. + */ + if (size < sizeof(element)) { + size = sizeof(element); + } mpctx->size = size; mpctx->maxalloc = UINT_MAX; mpctx->allocated = 0; diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index a32b33ae5a8..d9d23841496 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -137,6 +137,21 @@ ATF_TC_BODY(isc_mem, tc) { isc_mem_destroy(&localmctx); + result = isc_mem_createx2(0, 0, default_memalloc, default_memfree, + NULL, &localmctx, + ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + + result = isc_mempool_create(localmctx, 2, &mp1); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + + tmp = isc_mempool_get(mp1); + ATF_CHECK(tmp != NULL); + + isc_mempool_put(mp1, tmp); + + isc_mempool_destroy(&mp1); + isc_test_end(); }