Commit 7663d075 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Merge branch 'ondrej/fix-race-condition-in-dnstap-v9_11' into 'v9_11'

(v9_11) Fix race condition in cleanup part of dns_dt_create()

See merge request !1345
parents cf306bf3 8cdad8fe
Pipeline #8763 passed with stages
in 6 minutes and 25 seconds
......@@ -5,6 +5,9 @@
correctly and failed to add new lines between each
view. [GL !1327]
 
5132. [bug] Fix race condition in cleanup part of dns_dt_create().
[GL !1323]
5128. [bug] Refreshkeytime was not being updated for managed
keys zones. [GL #784]
 
......
......@@ -197,26 +197,30 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
generation++;
env = isc_mem_get(mctx, sizeof(dns_dtenv_t));
if (env == NULL)
CHECK(ISC_R_NOMEMORY);
memset(env, 0, sizeof(dns_dtenv_t));
env->magic = DTENV_MAGIC;
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);
CHECK(isc_refcount_init(&env->refcount, 1));
CHECK(isc_stats_create(mctx, &env->stats, dns_dnstapcounter_max));
env->path = isc_mem_strdup(mctx, path);
if (env->path == NULL)
CHECK(ISC_R_NOMEMORY);
fwopt = fstrm_writer_options_init();
if (fwopt == NULL)
if (fwopt == NULL) {
CHECK(ISC_R_NOMEMORY);
}
res = fstrm_writer_options_add_content_type(fwopt,
DNSTAP_CONTENT_TYPE,
sizeof(DNSTAP_CONTENT_TYPE) - 1);
if (res != fstrm_res_success)
if (res != fstrm_res_success) {
CHECK(ISC_R_FAILURE);
}
if (mode == dns_dtmode_file) {
ffwopt = fstrm_file_options_init();
......@@ -231,11 +235,13 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
env->path);
fw = fstrm_unix_writer_init(fuwopt, fwopt);
}
} else
} else {
CHECK(ISC_R_FAILURE);
}
if (fw == NULL)
if (fw == NULL) {
CHECK(ISC_R_FAILURE);
}
env->iothr = fstrm_iothr_init(*foptp, &fw);
if (env->iothr == NULL) {
......@@ -249,9 +255,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;
cleanup:
......@@ -265,15 +268,12 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
fstrm_writer_options_destroy(&fwopt);
if (result != ISC_R_SUCCESS) {
if (env != NULL) {
if (env->mctx != NULL)
isc_mem_detach(&env->mctx);
if (env->path != NULL)
isc_mem_free(mctx, env->path);
if (env->stats != NULL)
isc_stats_detach(&env->stats);
isc_mem_put(mctx, env, sizeof(dns_dtenv_t));
isc_mutex_destroy(&env->reopen_lock);
isc_mem_free(mctx, env->path);
if (env->stats != NULL) {
isc_stats_detach(&env->stats);
}
isc_mem_putanddetach(&env->mctx, env, sizeof(dns_dtenv_t));
}
return (result);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment