]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
mempool didn't work for sizes less than sizeof(void*)
authorMark Andrews <marka@isc.org>
Tue, 14 Aug 2018 07:13:20 +0000 (17:13 +1000)
committerEvan Hunt <each@isc.org>
Tue, 14 Aug 2018 16:12:41 +0000 (09:12 -0700)
(cherry picked from commit 5dd1beec8eb73690ade0da70144e1d64693aac18)

lib/isc/mem.c
lib/isc/tests/mem_test.c

index abb476cb94fd3a1568a72f87292ca0a3e1847fd6..3fec79585ac376d3607323f1ad7af114eef429f0 100644 (file)
@@ -1857,6 +1857,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;
index 95c7ce36916f0982a8325ea170d37393abc39f7a..22de74ff976948117c303c72b68778837a6c8f26 100644 (file)
@@ -135,6 +135,20 @@ ATF_TC_BODY(isc_mem, tc) {
 
        isc_mem_destroy(&localmctx);
 
+       result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
+                                 NULL, &localmctx, 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();
 }