]> 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 07:47:14 +0000 (03:47 -0400)
lib/isc/mem.c
lib/isc/tests/mem_test.c

index 766302d1e09dfda498ca24da3b734928fac4d184..aa3b900d6cc66fd9200e2c14774c68a3e31ed27c 100644 (file)
@@ -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;
index a32b33ae5a8da1b1703a8314d5f9f7aae05eceb3..d9d23841496af5ab9bbf93d529c982067c1ef60a 100644 (file)
@@ -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();
 }