mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Use library constructor/destructor to initialize OpenSSL
Instead of calling isc_tls_initialize()/isc_tls_destroy() explicitly use gcc/clang attributes on POSIX and DLLMain on Windows to initialize and shutdown OpenSSL library. This resolves the issue when isc_nm_create() / isc_nm_destroy() was called multiple times and it would call OpenSSL library destructors from isc_nm_destroy(). At the same time, since we now have introduced the ctor/dtor for libisc, this commit moves the isc_mem API initialization (the list of the contexts) and changes the isc_mem_checkdestroyed() to schedule the checking of memory context on library unload instead of executing the code immediately.
This commit is contained in:
@@ -117,7 +117,8 @@ struct stats {
|
||||
|
||||
static ISC_LIST(isc_mem_t) contexts;
|
||||
|
||||
static isc_once_t once = ISC_ONCE_INIT;
|
||||
static isc_once_t init_once = ISC_ONCE_INIT;
|
||||
static isc_once_t shut_once = ISC_ONCE_INIT;
|
||||
static isc_mutex_t contextslock;
|
||||
|
||||
/*%
|
||||
@@ -440,12 +441,29 @@ default_memfree(void *ptr) {
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_action(void) {
|
||||
mem_initialize(void) {
|
||||
isc_mutex_init(&contextslock);
|
||||
ISC_LIST_INIT(contexts);
|
||||
totallost = 0;
|
||||
}
|
||||
|
||||
void
|
||||
isc__mem_initialize(void) {
|
||||
RUNTIME_CHECK(isc_once_do(&init_once, mem_initialize) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
mem_shutdown(void) {
|
||||
isc__mem_checkdestroyed();
|
||||
|
||||
isc_mutex_destroy(&contextslock);
|
||||
}
|
||||
|
||||
void
|
||||
isc__mem_shutdown(void) {
|
||||
RUNTIME_CHECK(isc_once_do(&shut_once, mem_shutdown) == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
mem_create(isc_mem_t **ctxp, unsigned int flags) {
|
||||
REQUIRE(ctxp != NULL && *ctxp == NULL);
|
||||
@@ -457,8 +475,6 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) {
|
||||
STATIC_ASSERT(ALIGNMENT_SIZE >= sizeof(size_info),
|
||||
"alignment size too small");
|
||||
|
||||
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||
|
||||
ctx = default_memalloc(sizeof(*ctx));
|
||||
|
||||
*ctx = (isc_mem_t){
|
||||
@@ -1458,13 +1474,20 @@ print_contexts(FILE *file) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static atomic_uintptr_t checkdestroyed = ATOMIC_VAR_INIT(0);
|
||||
|
||||
void
|
||||
isc_mem_checkdestroyed(FILE *file) {
|
||||
#if !ISC_MEM_TRACKLINES
|
||||
UNUSED(file);
|
||||
#endif /* if !ISC_MEM_TRACKLINES */
|
||||
atomic_store_release(&checkdestroyed, (uintptr_t)file);
|
||||
}
|
||||
|
||||
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||
void
|
||||
isc__mem_checkdestroyed(void) {
|
||||
FILE *file = (FILE *)atomic_load_acquire(&checkdestroyed);
|
||||
|
||||
if (file == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOCK(&contextslock);
|
||||
if (!ISC_LIST_EMPTY(contexts)) {
|
||||
@@ -1597,8 +1620,6 @@ isc_mem_renderxml(void *writer0) {
|
||||
|
||||
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "contexts"));
|
||||
|
||||
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||
|
||||
LOCK(&contextslock);
|
||||
lost = totallost;
|
||||
for (ctx = ISC_LIST_HEAD(contexts); ctx != NULL;
|
||||
@@ -1739,7 +1760,6 @@ isc_mem_renderjson(void *memobj0) {
|
||||
json_object *memobj = (json_object *)memobj0;
|
||||
|
||||
memset(&summary, 0, sizeof(summary));
|
||||
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||
|
||||
ctxarray = json_object_new_array();
|
||||
CHECKMEM(ctxarray);
|
||||
|
Reference in New Issue
Block a user