From 0532dd1e1d126a5bda8efd65c09147a208ca85f1 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 26 Jun 2005 00:52:03 +0000 Subject: [PATCH] plug memory leak in GetErrorMessage --- bindings/java/src/jni/win32/util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bindings/java/src/jni/win32/util.c b/bindings/java/src/jni/win32/util.c index 3f52a575..a03ffd50 100644 --- a/bindings/java/src/jni/win32/util.c +++ b/bindings/java/src/jni/win32/util.c @@ -32,6 +32,7 @@ JNIEXPORT jstring SIGAR_JNI(win32_Win32_GetErrorMessage) (JNIEnv *env, jclass cls, jint error) { LPTSTR msg; + jstring str; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_IGNORE_INSERTS| @@ -39,7 +40,9 @@ JNIEXPORT jstring SIGAR_JNI(win32_Win32_GetErrorMessage) NULL, error, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR)&msg, 0, NULL); - return JENV->NewString(env, (const jchar *)msg, lstrlen(msg)); + str = JENV->NewString(env, (const jchar *)msg, lstrlen(msg)); + LocalFree(msg); + return str; } #ifdef __cplusplus