You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/07/22 07:00:55 UTC

[27/50] commons-crypto git commit: No need to save the libary pointer once initialised

No need to save the libary pointer once initialised

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/56894ba1
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/56894ba1
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/56894ba1

Branch: refs/heads/CRYPTO-1.0.0
Commit: 56894ba1f6770f8fd1791ecab5b8804b764cb194
Parents: b17af9d
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 18:07:20 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 18:07:20 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/crypto/cipher/OpenSslNative.c    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/56894ba1/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
index fd35f61..5d90c06 100644
--- a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
+++ b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
@@ -46,7 +46,6 @@ static EVP_CIPHER * (*dlsym_EVP_aes_128_ctr)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_256_cbc)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_192_cbc)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_128_cbc)(void);
-static void *openssl;
 #endif
 
 #ifdef WINDOWS
@@ -82,10 +81,15 @@ static __dlsym_EVP_aes_128_ctr dlsym_EVP_aes_128_ctr;
 static __dlsym_EVP_aes_256_cbc dlsym_EVP_aes_256_cbc;
 static __dlsym_EVP_aes_192_cbc dlsym_EVP_aes_192_cbc;
 static __dlsym_EVP_aes_128_cbc dlsym_EVP_aes_128_cbc;
-static HMODULE openssl;
 #endif
 
-static void loadAes(JNIEnv *env)
+#ifdef UNIX
+static void loadAes(JNIEnv *env, void *openssl)
+#endif
+
+#ifdef WINDOWS
+static void loadAes(JNIEnv *env, HMODULE openssl)
+#endif
 {
 #ifdef UNIX
   LOAD_DYNAMIC_SYMBOL(dlsym_EVP_aes_256_ctr, env, openssl, "EVP_aes_256_ctr");
@@ -117,11 +121,11 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
 {
   char msg[1000];
 #ifdef UNIX
-  openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
+  void *openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
 #endif
 
 #ifdef WINDOWS
-  openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
+  HMODULE openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
 #endif
 
   if (!openssl) {
@@ -172,7 +176,7 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
                       env, openssl, "EVP_CipherFinal_ex");
 #endif
 
-  loadAes(env);
+  loadAes(env, openssl);
   jthrowable jthr = (*env)->ExceptionOccurred(env);
   if (jthr) {
     (*env)->DeleteLocalRef(env, jthr);