summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/crypto_init.c')
-rw-r--r--src/lib/libcrypto/crypto_init.c28
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
29int OpenSSL_config(const char *); 31int OpenSSL_config(const char *);
30int OpenSSL_no_config(void); 32int OpenSSL_no_config(void);
31 33
34static pthread_once_t crypto_init_once = PTHREAD_ONCE_INIT;
32static pthread_t crypto_init_thread; 35static pthread_t crypto_init_thread;
36static int crypto_init_cleaned_up;
33 37
34static void 38static void
35OPENSSL_init_crypto_internal(void) 39OPENSSL_init_crypto_internal(void)
@@ -45,12 +49,15 @@ OPENSSL_init_crypto_internal(void)
45int 49int
46OPENSSL_init_crypto(uint64_t opts, const void *settings) 50OPENSSL_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
74void
75OPENSSL_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}