Memory reclamation by `call_rcu()` is asynchronous, so during shutdown
it can lose a race with the destruction of its memory context. When we
defer memory reclamation, we need to attach to the memory context to
indicate that it is still in use, but that is not enough to delay its
destruction. So, call `rcu_barrier()` in `isc_mem_destroy()` to wait
for pending RCU work to finish before proceeding to destroy the memory
context.
#include <isc/strerr.h>
#include <isc/string.h>
#include <isc/types.h>
+#include <isc/urcu.h>
#include <isc/util.h>
#ifdef HAVE_LIBXML2
ctx = *ctxp;
*ctxp = NULL;
+ /*
+ * wait for asynchronous memory reclamation to complete
+ * before checking for memory leaks
+ */
+ rcu_barrier();
+
#if ISC_MEM_TRACKLINES
if ((ctx->debugging & ISC_MEM_DEBUGTRACE) != 0) {
fprintf(stderr, "destroy mctx %p file %s line %u\n", ctx, file,