From 524d36bc2d7225718f7fe46d1d3446f5e051d9d1 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Fri, 26 Apr 2019 15:24:45 -0700 Subject: [PATCH] attach memory context sooner so that cleanup will work correctly (cherry picked from commit 0fd344e77a243803a14da3451c8999bfbf1ce3ff) --- lib/dns/dnstap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index d9f9d070ec..2e8375380e 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -211,12 +211,13 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path, env = isc_mem_get(mctx, sizeof(dns_dtenv_t)); memset(env, 0, sizeof(dns_dtenv_t)); + isc_mem_attach(mctx, &env->mctx); env->reopen_task = reopen_task; isc_mutex_init(&env->reopen_lock); env->reopen_queued = false; - env->path = isc_mem_strdup(mctx, path); + env->path = isc_mem_strdup(env->mctx, path); isc_refcount_init(&env->refcount, 1); - CHECK(isc_stats_create(mctx, &env->stats, dns_dnstapcounter_max)); + CHECK(isc_stats_create(env->mctx, &env->stats, dns_dnstapcounter_max)); fwopt = fstrm_writer_options_init(); if (fwopt == NULL) { @@ -265,8 +266,6 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path, env->fopt = *foptp; *foptp = NULL; - isc_mem_attach(mctx, &env->mctx); - env->magic = DTENV_MAGIC; *envp = env; @@ -282,7 +281,7 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path, if (result != ISC_R_SUCCESS) { isc_mutex_destroy(&env->reopen_lock); - isc_mem_free(mctx, env->path); + isc_mem_free(env->mctx, env->path); if (env->stats != NULL) { isc_stats_detach(&env->stats); }