Skip to content

Commit c7925f4

Browse files
committed
add call to DeleteGlobalRef for native CTX-level CRL callback, only affects JNI not JSSE
1 parent 062a63e commit c7925f4

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

native/com_wolfssl_WolfSSLContext.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ JNIEXPORT void JNICALL Java_com_wolfssl_WolfSSLContext_freeContext
330330
g_verifyCbIfaceObj = NULL;
331331
}
332332

333+
/* release global CRL callback object if set */
334+
if (g_crlCtxCbIfaceObj != NULL) {
335+
(*jenv)->DeleteGlobalRef(jenv, g_crlCtxCbIfaceObj);
336+
g_crlCtxCbIfaceObj = NULL;
337+
}
338+
333339
/* wolfSSL checks for null pointer */
334340
wolfSSL_CTX_free((WOLFSSL_CTX*)(uintptr_t)ctx);
335341
}
@@ -1528,25 +1534,34 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_setCRLCb
15281534

15291535
(void)jcl;
15301536

1531-
if (!jenv || !ctx || !cb) {
1537+
if (jenv == NULL || ctx == 0) {
15321538
return BAD_FUNC_ARG;
15331539
}
15341540

1535-
/* store Java CRL callback Interface object */
1536-
g_crlCtxCbIfaceObj = (*jenv)->NewGlobalRef(jenv, cb);
1541+
/* release global CRL callback object if set */
1542+
if (g_crlCtxCbIfaceObj != NULL) {
1543+
(*jenv)->DeleteGlobalRef(jenv, g_crlCtxCbIfaceObj);
1544+
g_crlCtxCbIfaceObj = NULL;
1545+
}
15371546

1538-
if (!g_crlCtxCbIfaceObj) {
1539-
excClass = (*jenv)->FindClass(jenv, "com/wolfssl/WolfSSLJNIException");
1540-
if ((*jenv)->ExceptionOccurred(jenv)) {
1541-
(*jenv)->ExceptionDescribe(jenv);
1542-
(*jenv)->ExceptionClear(jenv);
1547+
if (cb != NULL) {
1548+
/* store Java CRL callback Interface object */
1549+
g_crlCtxCbIfaceObj = (*jenv)->NewGlobalRef(jenv, cb);
1550+
1551+
if (!g_crlCtxCbIfaceObj) {
1552+
excClass = (*jenv)->FindClass(jenv,
1553+
"com/wolfssl/WolfSSLJNIException");
1554+
if ((*jenv)->ExceptionOccurred(jenv)) {
1555+
(*jenv)->ExceptionDescribe(jenv);
1556+
(*jenv)->ExceptionClear(jenv);
1557+
}
1558+
(*jenv)->ThrowNew(jenv, excClass,
1559+
"error storing global missing CTX CRL callback interface");
15431560
}
1544-
(*jenv)->ThrowNew(jenv, excClass,
1545-
"error storing global missing CTX CRL callback interface");
1546-
}
15471561

1548-
ret = wolfSSL_CTX_SetCRL_Cb((WOLFSSL_CTX*)(uintptr_t)ctx,
1549-
NativeCtxMissingCRLCallback);
1562+
ret = wolfSSL_CTX_SetCRL_Cb((WOLFSSL_CTX*)(uintptr_t)ctx,
1563+
NativeCtxMissingCRLCallback);
1564+
}
15501565

15511566
return ret;
15521567
#else

0 commit comments

Comments
 (0)