You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2023/11/24 17:19:03 UTC

(commons-crypto) branch master updated: CRYPTO-166 Library is reloaded multiple times

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d72f6c3 CRYPTO-166 Library is reloaded multiple times
8d72f6c3 is described below

commit 8d72f6c3c1e713030e1c0f6045394cf624eacdfd
Author: Sebb <se...@apache.org>
AuthorDate: Fri Nov 24 17:18:57 2023 +0000

    CRYPTO-166 Library is reloaded multiple times
---
 src/changes/changes.xml                                       | 1 +
 src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 971ada1a..25959d4a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@
   <body>
     <release version="1.2.1" date="202X-MM-DD" description="Minor release (Java 8, OpenSSL 1.1.1)">
       <!-- FIX -->
+      <action issue="CRYPTO-166" type="fix" dev="sebb">Library is reloaded multiple times</action>
       <action issue="CRYPTO-175" type="fix" dev="sebb">JNA tests rely on JNI code</action>
       <action issue="CRYPTO-178" type="fix" dev="sebb">OpenSslCryptoRandom.isNativeCodeEnabled() throws if library cannot be loaded</action>
       <action issue="CRYPTO-173" type="fix" dev="sebb">docker build does not work on macOS M1</action>
diff --git a/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c b/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
index 2dbaa92a..646ec715 100644
--- a/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
+++ b/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
@@ -72,6 +72,8 @@ static void get_methods(JNIEnv *env, HMODULE openssl)
   #endif
 }
 
+static bool loaded = false; // have we successfully loaded the library and the methods?
+
 static int load_library(JNIEnv *env)
 {
   HMODULE openssl = open_library(env); // calls THROW and returns 0 on error
@@ -79,7 +81,10 @@ static int load_library(JNIEnv *env)
   if (!openssl) {
     return 0;
   }
-  get_methods(env, openssl);
+  if (!loaded) {
+    get_methods(env, openssl);
+    loaded = true;
+  }
   return 1;
 }