mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
2982. [bug] Reference count dst keys. dst_key_attach() can be used
increment the reference count. Note: dns_tsigkey_createfromkey() callers should now always call dst_key_free() rather than setting it to NULL on success. [RT #22672]
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
|
||||
/*
|
||||
* Principal Author: Brian Wellington
|
||||
* $Id: dst_api.c,v 1.52 2010/12/02 23:22:42 marka Exp $
|
||||
* $Id: dst_api.c,v 1.53 2010/12/09 00:54:33 marka Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <isc/once.h>
|
||||
#include <isc/platform.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/time.h>
|
||||
@@ -1015,10 +1016,22 @@ dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2) {
|
||||
return (ISC_FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
dst_key_attach(dst_key_t *source, dst_key_t **target) {
|
||||
|
||||
REQUIRE(dst_initialized == ISC_TRUE);
|
||||
REQUIRE(target != NULL && *target == NULL);
|
||||
REQUIRE(VALID_KEY(source));
|
||||
|
||||
isc_refcount_increment(&source->refs, NULL);
|
||||
*target = source;
|
||||
}
|
||||
|
||||
void
|
||||
dst_key_free(dst_key_t **keyp) {
|
||||
isc_mem_t *mctx;
|
||||
dst_key_t *key;
|
||||
unsigned int refs;
|
||||
|
||||
REQUIRE(dst_initialized == ISC_TRUE);
|
||||
REQUIRE(keyp != NULL && VALID_KEY(*keyp));
|
||||
@@ -1026,6 +1039,11 @@ dst_key_free(dst_key_t **keyp) {
|
||||
key = *keyp;
|
||||
mctx = key->mctx;
|
||||
|
||||
isc_refcount_decrement(&key->refs, &refs);
|
||||
if (refs != 0)
|
||||
return;
|
||||
|
||||
isc_refcount_destroy(&key->refs);
|
||||
if (key->keydata.generic != NULL) {
|
||||
INSIST(key->func->destroy != NULL);
|
||||
key->func->destroy(key);
|
||||
@@ -1165,14 +1183,22 @@ get_key_struct(dns_name_t *name, unsigned int alg,
|
||||
memset(key, 0, sizeof(dst_key_t));
|
||||
key->magic = KEY_MAGIC;
|
||||
|
||||
result = isc_refcount_init(&key->refs, 1);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
key->key_name = isc_mem_get(mctx, sizeof(dns_name_t));
|
||||
if (key->key_name == NULL) {
|
||||
isc_refcount_destroy(&key->refs);
|
||||
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
||||
return (NULL);
|
||||
}
|
||||
dns_name_init(key->key_name, NULL);
|
||||
result = dns_name_dup(name, mctx, key->key_name);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_refcount_destroy(&key->refs);
|
||||
isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
|
||||
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
||||
return (NULL);
|
||||
|
Reference in New Issue
Block a user