diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 971ada1a5..25959d4a2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@
+ Library is reloaded multiple times
JNA tests rely on JNI code
OpenSslCryptoRandom.isNativeCodeEnabled() throws if library cannot be loaded
docker build does not work on macOS M1
diff --git a/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c b/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
index 2dbaa92ab..646ec715d 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;
}