<AWT Dev> [PATCH resend] Fix memory leak in wcstombsdmp
Alex Henrie
alexhenrie24 at gmail.com
Tue Dec 1 22:05:25 UTC 2015
# HG changeset patch
# User Alex Henrie <alexhenrie24 at gmail.com>
# Date 1448316746 25200
# Mon Nov 23 15:12:26 2015 -0700
# Node ID 50c079e1d06b196368da9edeb4ba9c8e9b8cf913
# Parent 8c9484fe1bb22b13e873ef8fcaeeff234e4dabca
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