<AWT Dev> [PATCH resend3] 8146317: Fix memory leak in wcstombsdmp
Alex Henrie
alexhenrie24 at gmail.com
Tue Jan 5 19:00:16 UTC 2016
# HG changeset patch
# User Alex Henrie <alexhenrie24 at gmail.com>
# Date 1448324612 25200
# Mon Nov 23 17:23:32 2015 -0700
# Node ID cbe4975f3f6ff997256340d7233f97ec93b5c034
# Parent 398904912c77deb6257c8d6b7bfa36192aeffe6a
8146317: Fix memory leak in wcstombsdmp
If a character cannot be represented in the current locale, wcstombs can
set errno to EILSEQ and return -1. In this case, the char buffer is not
returned because it contains garbage, so it needs to be freed.
diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
--- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
+++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
@@ -216,18 +216,20 @@ wcstombsdmp(wchar_t *wcs, int len)
mbs = (char *) malloc(n * sizeof(char));
if (mbs == NULL) {
THROW_OUT_OF_MEMORY_ERROR();
return NULL;
}
/* TODO: check return values... Handle invalid characters properly... */
- if (wcstombs(mbs, wcs, n) == (size_t)-1)
+ if (wcstombs(mbs, wcs, n) == (size_t)-1) {
+ free(mbs);
return NULL;
+ }
return mbs;
}
/*
* Returns True if the global reference is still in the list,
* otherwise False.
*/
More information about the awt-dev
mailing list