@@ -2193,6 +2193,31 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_setCRLCb
21932193
21942194#ifdef HAVE_CRL
21952195
2196+ /* Delete JNI local references created inside NativeCtxMissingCRLCallback() */
2197+ static void freeCtxMissingCRLCbLocalRefs (JNIEnv * jenv , jclass excClass ,
2198+ jobject crlCbObj , jclass crlClass , jstring missingUrl )
2199+ {
2200+ if (jenv == NULL ) {
2201+ return ;
2202+ }
2203+
2204+ if (missingUrl != NULL ) {
2205+ (* jenv )-> DeleteLocalRef (jenv , missingUrl );
2206+ }
2207+
2208+ if (crlClass != NULL ) {
2209+ (* jenv )-> DeleteLocalRef (jenv , crlClass );
2210+ }
2211+
2212+ if (crlCbObj != NULL ) {
2213+ (* jenv )-> DeleteLocalRef (jenv , crlCbObj );
2214+ }
2215+
2216+ if (excClass != NULL ) {
2217+ (* jenv )-> DeleteLocalRef (jenv , excClass );
2218+ }
2219+ }
2220+
21962221void NativeCtxMissingCRLCallback (const char * url )
21972222{
21982223 JNIEnv * jenv ;
@@ -2245,6 +2270,8 @@ void NativeCtxMissingCRLCallback(const char* url)
22452270
22462271 if (crlCbObj == NULL ) {
22472272 /* No Java callback registered, drop silently. */
2273+ freeCtxMissingCRLCbLocalRefs (jenv , excClass , crlCbObj , crlClass ,
2274+ missingUrl );
22482275 if (needsDetach ) {
22492276 (* g_vm )-> DetachCurrentThread (g_vm );
22502277 }
@@ -2261,6 +2288,8 @@ void NativeCtxMissingCRLCallback(const char* url)
22612288 if (!crlClass ) {
22622289 (* jenv )-> ThrowNew (jenv , excClass ,
22632290 "Can't get native WolfSSLMissingCRLCallback class reference" );
2291+ freeCtxMissingCRLCbLocalRefs (jenv , excClass , crlCbObj , crlClass ,
2292+ missingUrl );
22642293 if (needsDetach )
22652294 (* g_vm )-> DetachCurrentThread (g_vm );
22662295 return ;
@@ -2277,6 +2306,8 @@ void NativeCtxMissingCRLCallback(const char* url)
22772306
22782307 (* jenv )-> ThrowNew (jenv , excClass ,
22792308 "Error getting missingCRLCallback method from JNI" );
2309+ freeCtxMissingCRLCbLocalRefs (jenv , excClass , crlCbObj , crlClass ,
2310+ missingUrl );
22802311 if (needsDetach )
22812312 (* g_vm )-> DetachCurrentThread (g_vm );
22822313 return ;
@@ -2303,6 +2334,9 @@ void NativeCtxMissingCRLCallback(const char* url)
23032334 "Object reference invalid in NativeMissingCRLCallback" );
23042335 }
23052336
2337+ freeCtxMissingCRLCbLocalRefs (jenv , excClass , crlCbObj , crlClass ,
2338+ missingUrl );
2339+
23062340 if (needsDetach )
23072341 (* g_vm )-> DetachCurrentThread (g_vm );
23082342}
0 commit comments