File openssl-1.1.1-fips-fix-memory-leaks.patch of Package openssl-1_1.30140

---
 crypto/fips/fips.c                 |    8 ++++++++
 crypto/fips/fips_drbg_rand.c       |    6 ++++++
 crypto/include/internal/fips_int.h |    1 +
 crypto/init.c                      |    6 ++++++
 include/openssl/fips_rand.h        |    1 +
 5 files changed, 22 insertions(+)

--- a/crypto/fips/fips.c
+++ b/crypto/fips/fips.c
@@ -93,6 +93,14 @@ DEFINE_RUN_ONCE_STATIC(do_fips_lock_init
     return fips_lock != NULL && fips_owning_lock != NULL;
 }
 
+void FIPS_owning_thread_lock_cleanup(void)
+{
+    CRYPTO_THREAD_lock_free(fips_lock);
+    fips_lock = NULL;
+    CRYPTO_THREAD_lock_free(fips_owning_lock);
+    fips_owning_lock = NULL;
+}
+
 # define fips_w_lock()   CRYPTO_THREAD_write_lock(fips_lock)
 # define fips_w_unlock() CRYPTO_THREAD_unlock(fips_lock)
 # define fips_r_lock()   CRYPTO_THREAD_read_lock(fips_lock)
--- a/crypto/fips/fips_drbg_rand.c
+++ b/crypto/fips/fips_drbg_rand.c
@@ -84,6 +84,12 @@ DRBG_CTX *FIPS_get_default_drbg(void)
     return &ossl_dctx;
 }
 
+void FIPS_drbg_lock_cleanup(void)
+{
+    CRYPTO_THREAD_lock_free(fips_rand_lock);
+    fips_rand_lock = NULL;
+}
+
 static int fips_drbg_bytes(unsigned char *out, int count)
 {
     DRBG_CTX *dctx = &ossl_dctx;
--- a/crypto/include/internal/fips_int.h
+++ b/crypto/include/internal/fips_int.h
@@ -99,5 +99,6 @@ int fips_cipher_test(EVP_CIPHER_CTX *ctx
 void fips_set_selftest_fail(void);
 
 void FIPS_get_timevec(unsigned char *buf, unsigned long *pctr);
+void FIPS_owning_thread_lock_cleanup(void);
 
 #endif
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -27,6 +27,8 @@
 #include "internal/dso_conf.h"
 #include "internal/dso.h"
 #include "internal/store.h"
+#include "openssl/fips_rand.h"
+#include "internal/fips_int.h"
 
 static int stopped = 0;
 
@@ -597,6 +599,10 @@ void OPENSSL_cleanup(void)
     rand_cleanup_int();
     rand_drbg_cleanup_int();
     conf_modules_free_int();
+#ifdef OPENSSL_FIPS
+    FIPS_drbg_lock_cleanup();
+    FIPS_owning_thread_lock_cleanup();
+#endif
 #ifndef OPENSSL_NO_ENGINE
     engine_cleanup_int();
 #endif
--- a/include/openssl/fips_rand.h
+++ b/include/openssl/fips_rand.h
@@ -125,6 +125,7 @@ extern "C" {
 
     DRBG_CTX *FIPS_get_default_drbg(void);
     const RAND_METHOD *FIPS_drbg_method(void);
+    void FIPS_drbg_lock_cleanup(void);
 
     int FIPS_rand_set_method(const RAND_METHOD *meth);
     const RAND_METHOD *FIPS_rand_get_method(void);
openSUSE Build Service is sponsored by