IDEA-155938 Native memory leak in Harfbuzz integration code
This is now fixed in OpenJDK in a similar way (JDK-8148477, JDK-8158477), copy fix from there to avoid unnecessary divergence
diff --git a/src/share/native/sun/font/HBShaper.c b/src/share/native/sun/font/HBShaper.c
index c5168fe..bdbb6b9 100644
--- a/src/share/native/sun/font/HBShaper.c
+++ b/src/share/native/sun/font/HBShaper.c
@@ -271,10 +271,15 @@
hb_buffer_set_direction(buffer, direction);
chars = (*env)->GetCharArrayElements(env, text, NULL);
+ if ((*env)->ExceptionCheck(env)) {
+ hb_buffer_destroy(buffer);
+ hb_font_destroy(hbfont);
+ free((void*)jdkFontInfo);
+ return JNI_FALSE;
+ }
len = (*env)->GetArrayLength(env, text);
hb_buffer_add_utf16(buffer, chars, len, offset, limit-offset);
- (*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT);
hb_shape_full(hbfont, buffer, features, featureCount, 0);
glyphCount = hb_buffer_get_length(buffer);
@@ -303,6 +308,7 @@
hb_font_destroy(hbfont);
free((void*)jdkFontInfo);
if (features != NULL) free(features);
+ (*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT);
return JNI_TRUE;
}