[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/40769] New: A JNI memory leak in the Java_java_lang_VMSys
From: |
lineonking at gmail dot com |
Subject: |
[Bug classpath/40769] New: A JNI memory leak in the Java_java_lang_VMSystem_getenv native method |
Date: |
15 Jul 2009 23:48:17 -0000 |
The Java_java_lang_VMSystem_getenv native method may leak a memory when the
"envname" is NULL and the JVM returns a new memory for GetStringUTFChars. The
memory cell pointed by the "cname" is a JVM resource that must be deallocated
by calling ReleaseStringUTFChars.
-------------------------
JNIEXPORT jstring JNICALL
Java_java_lang_VMSystem_getenv (JNIEnv * env,
jclass klass __attribute__ ((__unused__)),
jstring jname)
{
const char *cname;
const char *envname;
cname = JCL_jstring_to_cstring (env, jname);
if (cname == NULL)
return NULL;
envname = getenv (cname);
if (envname == NULL)
return NULL;
JCL_free_cstring (env, jname, cname);
return (*env)->NewStringUTF (env, envname);
}
-------------------------
I propose the following patch of freeing the JVM resource as early as possible:
Index: java_lang_VMSystem.c
===================================================================
RCS file:
/sources/classpath/classpath/native/jni/java-lang/java_lang_VMSystem.c,v
retrieving revision 1.15
diff -r1.15 java_lang_VMSystem.c
151a152
> JCL_free_cstring (env, jname, cname);
155d155
< JCL_free_cstring (env, jname, cname);
--
Summary: A JNI memory leak in the Java_java_lang_VMSystem_getenv
native method
Product: classpath
Version: 0.98
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lineonking at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40769
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug classpath/40769] New: A JNI memory leak in the Java_java_lang_VMSystem_getenv native method,
lineonking at gmail dot com <=