Skip to content

Commit 8c01c9c

Browse files
committed
add call to DeleteGlobalRef for native WOLFSSL CRL callback, only currently applies to JNI not JSSE-only
1 parent 7597b5e commit 8c01c9c

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

native/com_wolfssl_WolfSSLSession.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,14 @@ JNIEXPORT void JNICALL Java_com_wolfssl_WolfSSLSession_freeSSL
957957
return;
958958
}
959959

960+
#ifdef HAVE_CRL
961+
/* release global CRL callback ref if registered */
962+
if (g_crlCbIfaceObj != NULL) {
963+
(*jenv)->DeleteGlobalRef(jenv, g_crlCbIfaceObj);
964+
g_crlCbIfaceObj = NULL;
965+
}
966+
#endif
967+
960968
/* native cleanup */
961969
wolfSSL_free((WOLFSSL*)(uintptr_t)ssl);
962970
ssl = 0;
@@ -2037,7 +2045,7 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_setCRLCb
20372045

20382046
(void)jcl;
20392047

2040-
if (!jenv || !cb) {
2048+
if (jenv == NULL) {
20412049
return BAD_FUNC_ARG;
20422050
}
20432051

@@ -2049,21 +2057,30 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_setCRLCb
20492057
return SSL_FAILURE;
20502058
}
20512059

2052-
if (!ssl) {
2060+
if (ssl == 0) {
20532061
(*jenv)->ThrowNew(jenv, excClass,
20542062
"Input WolfSSLSession object was null in "
20552063
"setCRLCb");
20562064
return SSL_FAILURE;
20572065
}
20582066

2059-
/* store Java CRL callback Interface object */
2060-
g_crlCbIfaceObj = (*jenv)->NewGlobalRef(jenv, cb);
2061-
if (!g_crlCbIfaceObj) {
2062-
(*jenv)->ThrowNew(jenv, excClass,
2063-
"Error storing global missingCRLCallback interface");
2067+
/* release global CRL callback ref if already registered */
2068+
if (g_crlCbIfaceObj != NULL) {
2069+
(*jenv)->DeleteGlobalRef(jenv, g_crlCbIfaceObj);
2070+
g_crlCbIfaceObj = NULL;
20642071
}
20652072

2066-
ret = wolfSSL_SetCRL_Cb((WOLFSSL*)(uintptr_t)ssl, NativeMissingCRLCallback);
2073+
if (cb != NULL) {
2074+
/* store Java CRL callback Interface object */
2075+
g_crlCbIfaceObj = (*jenv)->NewGlobalRef(jenv, cb);
2076+
if (g_crlCbIfaceObj == NULL) {
2077+
(*jenv)->ThrowNew(jenv, excClass,
2078+
"Error storing global missingCRLCallback interface");
2079+
}
2080+
2081+
ret = wolfSSL_SetCRL_Cb((WOLFSSL*)(uintptr_t)ssl,
2082+
NativeMissingCRLCallback);
2083+
}
20672084

20682085
return ret;
20692086
#else

0 commit comments

Comments
 (0)