8148477: Native memory leak in font layout subsystem
authorprr
Thu, 28 Jul 2016 09:53:08 -0700
changeset 40155 b909b3a9277c
parent 40154 de35b2251350
child 40156 5b4bb91fd355
8148477: Native memory leak in font layout subsystem Reviewed-by: serb
jdk/src/java.desktop/share/native/libfontmanager/HBShaper.c
--- a/jdk/src/java.desktop/share/native/libfontmanager/HBShaper.c	Thu Jul 28 06:02:40 2016 -0700
+++ b/jdk/src/java.desktop/share/native/libfontmanager/HBShaper.c	Thu Jul 28 09:53:08 2016 -0700
@@ -278,6 +278,12 @@
      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);
@@ -309,6 +315,7 @@
      hb_font_destroy(hbfont);
      free((void*)jdkFontInfo);
      if (features != NULL) free(features);
+     (*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT);
 
      return JNI_TRUE;
 }