<AWT Dev> [PATCH] Fix memory leak in wcstombsdmp
Alex Henrie
alexhenrie24 at gmail.com
Tue Nov 24 00:28:23 UTC 2015
# HG changeset patch
# User Alex Henrie <alexhenrie24 at gmail.com>
# Date 1448324612 25200
# Mon Nov 23 17:23:32 2015 -0700
# Node ID af70128e2f70c246dae3a8d51e70fa097c97a552
# Parent e9b7db0341f63a8835e5d7da155683c004454b25
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