From 982b491d7c3876284e6ce6337f1abc9497be08ce Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Wed, 31 Aug 2022 12:30:38 +0000 Subject: [PATCH 1/2] Add mctx attach/detach when creating/destroying a memory pool This should make sure that the memory context is not destroyed before the memory pool, which is using the context. (cherry picked from commit e97c3eea954e055634b72c21325d2611e960ee94) --- lib/isc/mem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index b2e53a31e1..f828672119 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -1183,8 +1183,6 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, mpctx = isc_mem_get(mctx, sizeof(isc_mempool_t)); *mpctx = (isc_mempool_t){ - .magic = MEMPOOL_MAGIC, - .mctx = mctx, .size = size, .freemax = 1, .fillcount = 1, @@ -1197,6 +1195,9 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, } #endif /* ISC_MEM_TRACKLINES */ + isc_mem_attach(mctx, &mpctx->mctx); + mpctx->magic = MEMPOOL_MAGIC; + *mpctxp = (isc_mempool_t *)mpctx; MCTXLOCK(mctx); @@ -1266,7 +1267,7 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) { mpctx->magic = 0; - isc_mem_put(mpctx->mctx, mpctx, sizeof(isc_mempool_t)); + isc_mem_putanddetach(&mpctx->mctx, mpctx, sizeof(isc_mempool_t)); } void * From 1017083de70b77f365ec59b94c52ad4caa9bb3a3 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Wed, 31 Aug 2022 12:35:53 +0000 Subject: [PATCH 2/2] Add CHANGES note for [GL #3515] (cherry picked from commit 362ead8d85ade3923aaa0346bf7443c811c22bb7) --- CHANGES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 58a84055f4..37be7d3858 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +5953. [bug] Fix a crash on shutdown in delete_trace_entry(). Add + mctx attach/detach pair to make sure that the memory + context used by a memory pool is not destroyed before + the memory pool itself. [GL #3515] + 5952. [bug] Use quotes around address strings in YAML output. [GL #3511]