mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
correctly attach and detach memory context
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
#include "dst_internal.h"
|
#include "dst_internal.h"
|
||||||
#include "dst_openssl.h"
|
#include "dst_openssl.h"
|
||||||
|
|
||||||
static isc_mem_t *dst__memory_pool = NULL;
|
static isc_mem_t *dst__mctx = NULL;
|
||||||
|
|
||||||
#if !defined(OPENSSL_NO_ENGINE)
|
#if !defined(OPENSSL_NO_ENGINE)
|
||||||
#include <openssl/engine.h>
|
#include <openssl/engine.h>
|
||||||
@@ -103,8 +103,8 @@ isc_result_t
|
|||||||
dst__openssl_init(isc_mem_t *mctx, const char *engine) {
|
dst__openssl_init(isc_mem_t *mctx, const char *engine) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
|
||||||
REQUIRE(dst__memory_pool == NULL);
|
REQUIRE(dst__mctx == NULL);
|
||||||
dst__memory_pool = mctx;
|
isc_mem_attach(mctx, &dst__mctx);
|
||||||
|
|
||||||
#if defined(OPENSSL_NO_ENGINE)
|
#if defined(OPENSSL_NO_ENGINE)
|
||||||
UNUSED(engine);
|
UNUSED(engine);
|
||||||
@@ -114,7 +114,7 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) {
|
|||||||
|
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
|
||||||
nlocks = CRYPTO_num_locks();
|
nlocks = CRYPTO_num_locks();
|
||||||
locks = isc_mem_allocate(dst__memory_pool, sizeof(isc_mutex_t) * nlocks);
|
locks = isc_mem_allocate(dst__mctx, sizeof(isc_mutex_t) * nlocks);
|
||||||
if (locks == NULL)
|
if (locks == NULL)
|
||||||
return (ISC_R_NOMEMORY);
|
return (ISC_R_NOMEMORY);
|
||||||
result = isc_mutexblock_init(locks, nlocks);
|
result = isc_mutexblock_init(locks, nlocks);
|
||||||
@@ -183,7 +183,7 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) {
|
|||||||
CRYPTO_set_locking_callback(NULL);
|
CRYPTO_set_locking_callback(NULL);
|
||||||
DESTROYMUTEXBLOCK(locks, nlocks);
|
DESTROYMUTEXBLOCK(locks, nlocks);
|
||||||
cleanup_mutexalloc:
|
cleanup_mutexalloc:
|
||||||
isc_mem_free(dst__memory_pool, locks);
|
isc_mem_free(dst__mctx, locks);
|
||||||
locks = NULL;
|
locks = NULL;
|
||||||
#endif
|
#endif
|
||||||
return (result);
|
return (result);
|
||||||
@@ -220,12 +220,13 @@ dst__openssl_destroy(void) {
|
|||||||
if (locks != NULL) {
|
if (locks != NULL) {
|
||||||
CRYPTO_set_locking_callback(NULL);
|
CRYPTO_set_locking_callback(NULL);
|
||||||
DESTROYMUTEXBLOCK(locks, nlocks);
|
DESTROYMUTEXBLOCK(locks, nlocks);
|
||||||
isc_mem_free(dst__memory_pool, locks);
|
isc_mem_free(dst__mctx, locks);
|
||||||
locks = NULL;
|
locks = NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
OPENSSL_cleanup();
|
OPENSSL_cleanup();
|
||||||
#endif
|
#endif
|
||||||
|
isc_mem_detach(&dst__mctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
|
Reference in New Issue
Block a user