Skip to content

Commit 062a63e

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

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

native/com_wolfssl_WolfSSLContext.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ JNIEXPORT void JNICALL Java_com_wolfssl_WolfSSLContext_freeContext
324324
(void)jenv;
325325
(void)jcl;
326326

327+
/* release verify callback object if set */
328+
if (g_verifyCbIfaceObj != NULL) {
329+
(*jenv)->DeleteGlobalRef(jenv, g_verifyCbIfaceObj);
330+
g_verifyCbIfaceObj = NULL;
331+
}
332+
327333
/* wolfSSL checks for null pointer */
328334
wolfSSL_CTX_free((WOLFSSL_CTX*)(uintptr_t)ctx);
329335
}
@@ -333,13 +339,23 @@ JNIEXPORT void JNICALL Java_com_wolfssl_WolfSSLContext_setVerify(JNIEnv* jenv,
333339
{
334340
(void)jcl;
335341

342+
if (jenv == NULL) {
343+
return;
344+
}
345+
346+
/* release verify callback object if set before */
347+
if (g_verifyCbIfaceObj != NULL) {
348+
(*jenv)->DeleteGlobalRef(jenv, g_verifyCbIfaceObj);
349+
g_verifyCbIfaceObj = NULL;
350+
}
351+
336352
if (!callbackIface) {
337353
wolfSSL_CTX_set_verify((WOLFSSL_CTX*)(uintptr_t)ctx, mode, NULL);
338-
} else {
339-
354+
}
355+
else {
340356
/* store Java verify Interface object */
341357
g_verifyCbIfaceObj = (*jenv)->NewGlobalRef(jenv, callbackIface);
342-
if (!g_verifyCbIfaceObj) {
358+
if (g_verifyCbIfaceObj == NULL) {
343359
printf("error storing global callback interface\n");
344360
}
345361

0 commit comments

Comments
 (0)