summaryrefslogtreecommitdiff
path: root/lib/dns/dst_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dns/dst_api.c')
-rw-r--r--lib/dns/dst_api.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c
index 680a0184319e..5834a58223f0 100644
--- a/lib/dns/dst_api.c
+++ b/lib/dns/dst_api.c
@@ -1,5 +1,5 @@
/*
- * Portions Copyright (C) 2004-2013, 2015 Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 2004-2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -302,12 +302,15 @@ dst_context_create2(dst_key_t *key, isc_mem_t *mctx,
dctx = isc_mem_get(mctx, sizeof(dst_context_t));
if (dctx == NULL)
return (ISC_R_NOMEMORY);
- dctx->key = key;
- dctx->mctx = mctx;
+ memset(dctx, 0, sizeof(*dctx));
+ dst_key_attach(key, &dctx->key);
+ isc_mem_attach(mctx, &dctx->mctx);
dctx->category = category;
result = key->func->createctx(key, dctx);
if (result != ISC_R_SUCCESS) {
- isc_mem_put(mctx, dctx, sizeof(dst_context_t));
+ if (dctx->key != NULL)
+ dst_key_free(&dctx->key);
+ isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(dst_context_t));
return (result);
}
dctx->magic = CTX_MAGIC;
@@ -324,8 +327,10 @@ dst_context_destroy(dst_context_t **dctxp) {
dctx = *dctxp;
INSIST(dctx->key->func->destroyctx != NULL);
dctx->key->func->destroyctx(dctx);
+ if (dctx->key != NULL)
+ dst_key_free(&dctx->key);
dctx->magic = 0;
- isc_mem_put(dctx->mctx, dctx, sizeof(dst_context_t));
+ isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(dst_context_t));
*dctxp = NULL;
}