diff options
| author | jsing <> | 2022-09-03 17:47:47 +0000 |
|---|---|---|
| committer | jsing <> | 2022-09-03 17:47:47 +0000 |
| commit | f1083ba41574ef4e529cc2ea4ff2aa685c4833cd (patch) | |
| tree | 6da083f1c09ce39a19ff47ac81c6e23adb5057bc /src/lib/libcrypto/crypto_init.c | |
| parent | e4165d18fd04cae0b27804487fe3e65d1e9d1d9e (diff) | |
| download | openbsd-f1083ba41574ef4e529cc2ea4ff2aa685c4833cd.tar.gz openbsd-f1083ba41574ef4e529cc2ea4ff2aa685c4833cd.tar.bz2 openbsd-f1083ba41574ef4e529cc2ea4ff2aa685c4833cd.zip | |
Prepare to provide OPENSSL_cleanup.
OPENSSL_cleanup() cleans up and deallocates memory in use by the library.
There are a couple of use cases for this, primarily related to memory
leak testing. This will not be called automatically in LibreSSL, which
means that OpenSSL's OPENSSL_NO_INIT_ATEXIT is implied. If code wants to
clean up then they need to explicitly call this themselves.
ok tb@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/crypto_init.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c index 67e7920890..69ba62991e 100644 --- a/src/lib/libcrypto/crypto_init.c +++ b/src/lib/libcrypto/crypto_init.c | |||
| @@ -19,17 +19,21 @@ | |||
| 19 | #include <pthread.h> | 19 | #include <pthread.h> |
| 20 | #include <stdio.h> | 20 | #include <stdio.h> |
| 21 | 21 | ||
| 22 | #include <openssl/objects.h> | ||
| 23 | #include <openssl/conf.h> | 22 | #include <openssl/conf.h> |
| 24 | #include <openssl/evp.h> | 23 | #include <openssl/engine.h> |
| 25 | #include <openssl/err.h> | 24 | #include <openssl/err.h> |
| 25 | #include <openssl/evp.h> | ||
| 26 | #include <openssl/objects.h> | ||
| 26 | 27 | ||
| 27 | #include "cryptlib.h" | 28 | #include "cryptlib.h" |
| 29 | #include "x509_issuer_cache.h" | ||
| 28 | 30 | ||
| 29 | int OpenSSL_config(const char *); | 31 | int OpenSSL_config(const char *); |
| 30 | int OpenSSL_no_config(void); | 32 | int OpenSSL_no_config(void); |
| 31 | 33 | ||
| 34 | static pthread_once_t crypto_init_once = PTHREAD_ONCE_INIT; | ||
| 32 | static pthread_t crypto_init_thread; | 35 | static pthread_t crypto_init_thread; |
| 36 | static int crypto_init_cleaned_up; | ||
| 33 | 37 | ||
| 34 | static void | 38 | static void |
| 35 | OPENSSL_init_crypto_internal(void) | 39 | OPENSSL_init_crypto_internal(void) |
| @@ -45,12 +49,15 @@ OPENSSL_init_crypto_internal(void) | |||
| 45 | int | 49 | int |
| 46 | OPENSSL_init_crypto(uint64_t opts, const void *settings) | 50 | OPENSSL_init_crypto(uint64_t opts, const void *settings) |
| 47 | { | 51 | { |
| 48 | static pthread_once_t once = PTHREAD_ONCE_INIT; | 52 | if (crypto_init_cleaned_up) { |
| 53 | CRYPTOerror(ERR_R_INIT_FAIL); | ||
| 54 | return 0; | ||
| 55 | } | ||
| 49 | 56 | ||
| 50 | if (pthread_equal(pthread_self(), crypto_init_thread)) | 57 | if (pthread_equal(pthread_self(), crypto_init_thread)) |
| 51 | return 1; /* don't recurse */ | 58 | return 1; /* don't recurse */ |
| 52 | 59 | ||
| 53 | if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0) | 60 | if (pthread_once(&crypto_init_once, OPENSSL_init_crypto_internal) != 0) |
| 54 | return 0; | 61 | return 0; |
| 55 | 62 | ||
| 56 | if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) && | 63 | if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) && |
| @@ -63,3 +70,16 @@ OPENSSL_init_crypto(uint64_t opts, const void *settings) | |||
| 63 | 70 | ||
| 64 | return 1; | 71 | return 1; |
| 65 | } | 72 | } |
| 73 | |||
| 74 | void | ||
| 75 | OPENSSL_cleanup(void) | ||
| 76 | { | ||
| 77 | /* This currently calls init... */ | ||
| 78 | ERR_free_strings(); | ||
| 79 | |||
| 80 | ENGINE_cleanup(); | ||
| 81 | EVP_cleanup(); | ||
| 82 | x509_issuer_cache_free(); | ||
| 83 | |||
| 84 | crypto_init_cleaned_up = 1; | ||
| 85 | } | ||
