<AWT Dev> Proposal: Memory leak issue on awt_InputMethod.c
Phil Race
philip.race at oracle.com
Wed Jun 27 21:06:53 UTC 2018
On 06/27/2018 06:45 AM, Ichiroh Takiguchi wrote:
> Hello,
>
> I should post this mail before starting JDK11 RDP1.
Already too too late for that, but although this looks like a bug - and
the correct fix -
the bug has been there forever .. since JDK 1.2 in 1998 !
That makes it a 20 year old bug, so I don't think we need to treat it as
urgent
for JDK 11.
-phil.
>
> I found memory leak issue on awt_InputMethod.c.
>
> See src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c.
> On line 1117, memory area was allocated by malloc(), but free() is
> missing
> ===========================================
> 1099 if (text->feedback != NULL) {
> 1100 int cnt;
> 1101 jint *tmpstyle;
> 1102
> 1103 style = (*env)->NewIntArray(env, text->length);
> 1104 if (JNU_IsNull(env, style)) {
> 1105 (*env)->ExceptionClear(env);
> 1106 THROW_OUT_OF_MEMORY_ERROR();
> 1107 goto finally;
> 1108 }
> 1109
> 1110 if (sizeof(XIMFeedback) == sizeof(jint)) {
> 1111 /*
> 1112 * Optimization to avoid copying the array
> 1113 */
> 1114 (*env)->SetIntArrayRegion(env, style, 0,
> 1115 text->length, (jint
> *)text->feedback);
> 1116 } else {
> 1117 tmpstyle = (jint
> *)malloc(sizeof(jint)*(text->length));
> 1118 if (tmpstyle == (jint *) NULL) {
> 1119 THROW_OUT_OF_MEMORY_ERROR();
> 1120 goto finally;
> 1121 }
> 1122 for (cnt = 0; cnt < (int)text->length; cnt++)
> 1123 tmpstyle[cnt] = text->feedback[cnt];
> 1124 (*env)->SetIntArrayRegion(env, style, 0,
> 1125 text->length, (jint
> *)tmpstyle);
> 1126 }
> 1127 }
> ===========================================
> In my investigation, malloc() was called on RHEL7 x86_64 with Japanese
> Input Method.
>
> I'd like to obtain a sponsor for this patch.
> --------
> --- old/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c
> 2018-06-27 02:03:48.134991703 +0900
> +++ new/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c
> 2018-06-27 02:03:47.493005265 +0900
> @@ -1148,6 +1148,7 @@
> tmpstyle[cnt] = text->feedback[cnt];
> (*env)->SetIntArrayRegion(env, style, 0,
> text->length, (jint
> *)tmpstyle);
> + free(tmpstyle);
> }
> }
> }
> --- old/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
> 2018-06-27 02:03:49.040972563 +0900
> +++ new/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
> 2018-06-27 02:03:48.391986274 +0900
> @@ -1123,6 +1123,7 @@
> tmpstyle[cnt] = text->feedback[cnt];
> (*env)->SetIntArrayRegion(env, style, 0,
> text->length, (jint
> *)tmpstyle);
> + free(tmpstyle);
> }
> }
> }
> --------
>
> Thanks,
> Ichiroh Takiguchi
> IBM Japan, Ltd.
>
More information about the awt-dev
mailing list