diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index c8b12911bb..0e5bde922f 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -709,8 +709,6 @@ main(int argc, char **argv) { cfg_parser_destroy(&parser); - dns_name_destroy(); - isc_log_destroy(&logc); isc_mem_destroy(&mctx); diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index de6bb94b8e..67613de41d 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -85,9 +85,9 @@ usage(void) { static void destroy(void) { - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); - dns_name_destroy(); + } } /*% main processing routine */ diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index bc712a1ad0..b9bc11603b 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -4252,7 +4252,6 @@ destroy_libs(void) { result = dns_name_settotextfilter(NULL); check_result(result, "dns_name_settotextfilter"); #endif /* HAVE_LIBIDN2 */ - dns_name_destroy(); if (commctx != NULL) { debug("freeing commctx"); diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index 4923fe6e8a..95ba8e9e7e 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -517,7 +517,6 @@ main(int argc, char **argv) { } cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) { isc_mem_stats(mctx, stdout); } diff --git a/bin/dnssec/dnssec-importkey.c b/bin/dnssec/dnssec-importkey.c index 964efcad0e..4a4684d741 100644 --- a/bin/dnssec/dnssec-importkey.c +++ b/bin/dnssec/dnssec-importkey.c @@ -439,7 +439,6 @@ main(int argc, char **argv) { dns_rdataset_disassociate(&rdataset); cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index e9dfe36f4f..4bc653f3a5 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -694,7 +694,6 @@ main(int argc, char **argv) { cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) isc_mem_stats(mctx, stdout); isc_mem_free(mctx, label); diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 40cffe2168..220cbe7a00 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -1222,7 +1222,6 @@ main(int argc, char **argv) { cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 7682a178e9..8008ed7712 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -3922,7 +3922,6 @@ main(int argc, char *argv[]) { cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); diff --git a/bin/dnssec/dnssec-verify.c b/bin/dnssec/dnssec-verify.c index 483577ef4f..29894c9e81 100644 --- a/bin/dnssec/dnssec-verify.c +++ b/bin/dnssec/dnssec-verify.c @@ -335,7 +335,6 @@ main(int argc, char *argv[]) { cleanup_logging(&log); dst_lib_destroy(); - dns_name_destroy(); if (verbose > 10) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); diff --git a/bin/named/main.c b/bin/named/main.c index 10e4f536a0..f1c14c511d 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -1329,8 +1329,6 @@ cleanup(void) { dlz_dlopen_clear(); #endif - dns_name_destroy(); - isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE, "exiting"); diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index a272b14a0f..4b4ce5cfad 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -3210,9 +3210,6 @@ cleanup(void) { ddebug("Shutting down timer manager"); isc_timermgr_destroy(&timermgr); - ddebug("Destroying name state"); - dns_name_destroy(); - ddebug("Removing log context"); isc_log_destroy(&glctx); diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index d9f32a4507..cc91793859 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -1022,8 +1022,6 @@ main(int argc, char **argv) { isc_mem_put(rndc_mctx, args, argslen); isccc_ccmsg_invalidate(&ccmsg); - dns_name_destroy(); - isc_buffer_free(&databuf); if (show_final_mem) diff --git a/bin/tests/system/rsabigexponent/bigkey.c b/bin/tests/system/rsabigexponent/bigkey.c index d01d264832..a1c4a01c4f 100644 --- a/bin/tests/system/rsabigexponent/bigkey.c +++ b/bin/tests/system/rsabigexponent/bigkey.c @@ -145,7 +145,6 @@ main(int argc, char **argv) { isc_log_setcontext(NULL); dns_log_setcontext(NULL); dst_lib_destroy(); - dns_name_destroy(); isc_mem_destroy(&mctx); return (0); #else /* !USE_PKCS11 */ diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index 6b50492491..2c051265fc 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -197,8 +197,8 @@ LIBDNS_EXTERNAL_DATA extern const dns_name_t *dns_wildcardname; * 'target' is the buffer to be converted. The region to be converted * is from 'buffer'->base + 'used_org' to the end of the used region. */ -typedef isc_result_t (*dns_name_totextfilter_t)(isc_buffer_t *target, - unsigned int used_org); +typedef isc_result_t (dns_name_totextfilter_t)(isc_buffer_t *target, + unsigned int used_org); /*** *** Initialization @@ -1217,7 +1217,7 @@ dns_name_fromstring2(dns_name_t *target, const char *src, */ isc_result_t -dns_name_settotextfilter(dns_name_totextfilter_t proc); +dns_name_settotextfilter(dns_name_totextfilter_t *proc); /*%< * Set / clear a thread specific function 'proc' to be called at the * end of dns_name_totext(). @@ -1296,18 +1296,6 @@ dns_name_internalwildcard(const dns_name_t *name); * \li 'name' to be valid. */ -void -dns_name_destroy(void); -/*%< - * Cleanup dns_name_settotextfilter() / dns_name_totext() state. - * - * This should be called as part of the final cleanup process. - * - * Note: dns_name_settotextfilter(NULL); should be called for all - * threads which have called dns_name_settotextfilter() with a - * non-NULL argument prior to calling dns_name_destroy(); - */ - bool dns_name_isdnssd(const dns_name_t *owner); /*%< diff --git a/lib/dns/name.c b/lib/dns/name.c index 3bb2e4fcf8..82b546429e 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -163,11 +163,7 @@ LIBDNS_EXTERNAL_DATA const dns_name_t *dns_wildcardname = &wild; /* * dns_name_t to text post-conversion procedure. */ -static int thread_key_initialized = 0; -static isc_mutex_t thread_key_mutex; -static isc_mem_t *thread_key_mctx = NULL; -static isc_thread_key_t totext_filter_proc_key; -static isc_once_t once = ISC_ONCE_INIT; +ISC_THREAD_LOCAL dns_name_totextfilter_t *totext_filter_proc = NULL; static void set_offsets(const dns_name_t *name, unsigned char *offsets, @@ -1272,52 +1268,6 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, return (ISC_R_SUCCESS); } -static void -free_specific(void *arg) { - dns_name_totextfilter_t *mem = arg; - isc_mem_put(thread_key_mctx, mem, sizeof(*mem)); - /* Stop use being called again. */ - (void)isc_thread_key_setspecific(totext_filter_proc_key, NULL); -} - -static void -thread_key_mutex_init(void) { - isc_mutex_init(&thread_key_mutex); -} - -static isc_result_t -totext_filter_proc_key_init(void) { - isc_result_t result; - - /* - * We need the call to isc_once_do() to support profiled mutex - * otherwise thread_key_mutex could be initialized at compile time. - */ - result = isc_once_do(&once, thread_key_mutex_init); - if (result != ISC_R_SUCCESS) - return (result); - - if (!thread_key_initialized) { - LOCK(&thread_key_mutex); - if (thread_key_mctx == NULL) { - isc_mem_create(&thread_key_mctx); - } - isc_mem_setname(thread_key_mctx, "threadkey", NULL); - isc_mem_setdestroycheck(thread_key_mctx, false); - - if (!thread_key_initialized && - isc_thread_key_create(&totext_filter_proc_key, - free_specific) != 0) { - result = ISC_R_FAILURE; - isc_mem_detach(&thread_key_mctx); - } else { - thread_key_initialized = 1; - } - UNLOCK(&thread_key_mutex); - } - return (result); -} - isc_result_t dns_name_totext(const dns_name_t *name, bool omit_final_dot, isc_buffer_t *target) @@ -1346,9 +1296,6 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, unsigned int labels; bool saw_root = false; unsigned int oused; - dns_name_totextfilter_t *mem; - dns_name_totextfilter_t totext_filter_proc = NULL; - isc_result_t result; bool omit_final_dot = ((options & DNS_NAME_OMITFINALDOT) != 0); /* @@ -1360,9 +1307,6 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, oused = target->used; - result = totext_filter_proc_key_init(); - if (result != ISC_R_SUCCESS) - return (result); ndata = name->ndata; nlen = name->length; labels = name->labels; @@ -1502,11 +1446,9 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, } isc_buffer_add(target, tlen - trem); - mem = isc_thread_key_getspecific(totext_filter_proc_key); - if (mem != NULL) - totext_filter_proc = *mem; - if (totext_filter_proc != NULL) - return ((*totext_filter_proc)(target, oused)); + if (totext_filter_proc != NULL) { + return ((totext_filter_proc)(target, oused)); + } return (ISC_R_SUCCESS); } @@ -2320,40 +2262,23 @@ dns_name_print(const dns_name_t *name, FILE *stream) { } isc_result_t -dns_name_settotextfilter(dns_name_totextfilter_t proc) { - isc_result_t result; - dns_name_totextfilter_t *mem; - int res; - - result = totext_filter_proc_key_init(); - if (result != ISC_R_SUCCESS) - return (result); - +dns_name_settotextfilter(dns_name_totextfilter_t *proc) { /* * If we already have been here set / clear as appropriate. - * Otherwise allocate memory. */ - mem = isc_thread_key_getspecific(totext_filter_proc_key); - if (mem != NULL && proc != NULL) { - *mem = proc; + if (totext_filter_proc != NULL && proc != NULL) { + if (totext_filter_proc == proc) { + return (ISC_R_SUCCESS); + } + } + if (proc == NULL && totext_filter_proc != NULL) { + totext_filter_proc = NULL; return (ISC_R_SUCCESS); } - if (proc == NULL) { - if (mem != NULL) - isc_mem_put(thread_key_mctx, mem, sizeof(*mem)); - res = isc_thread_key_setspecific(totext_filter_proc_key, NULL); - if (res != 0) - result = ISC_R_UNEXPECTED; - return (result); - } - mem = isc_mem_get(thread_key_mctx, sizeof(*mem)); - *mem = proc; - if (isc_thread_key_setspecific(totext_filter_proc_key, mem) != 0) { - isc_mem_put(thread_key_mctx, mem, sizeof(*mem)); - result = ISC_R_UNEXPECTED; - } - return (result); + totext_filter_proc = proc; + + return (ISC_R_SUCCESS); } void @@ -2511,21 +2436,6 @@ dns_name_copynf(const dns_name_t *source, dns_name_t *dest) RUNTIME_CHECK(name_copy(source, dest, dest->buffer) == ISC_R_SUCCESS); } -void -dns_name_destroy(void) { - RUNTIME_CHECK(isc_once_do(&once, thread_key_mutex_init) - == ISC_R_SUCCESS); - - LOCK(&thread_key_mutex); - if (thread_key_initialized) { - isc_mem_detach(&thread_key_mctx); - isc_thread_key_delete(totext_filter_proc_key); - thread_key_initialized = 0; - } - UNLOCK(&thread_key_mutex); - -} - /* * Service Discovery Prefixes RFC 6763. */ diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index b1a02a0f68..2eef22497c 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -584,7 +584,6 @@ dns_name_concatenate dns_name_copy dns_name_copynf dns_name_countlabels -dns_name_destroy dns_name_digest dns_name_downcase dns_name_dup