logo       

Bug in java_nio_VMDirectByteBuffer.c: msg#00124

java.classpath.patches

Subject: Bug in java_nio_VMDirectByteBuffer.c

There is a bug in java_nio_VMDirectByteBuffer.c in the function
Java_java_nio_VMDirectByteBuffer_init().

This function sets "classRawData", which is a static variable of type
jclass, from the result of calling (*env)->FindClass(), and then returns,
and then other JNI functions try to use this variable from within different
JNI invocations.

This is broken because the local native reference that was created by
(*env)->FindClass() goes away when Java_java_nio_VMDirectByteBuffer_init()
returns (not to mention that it could be used from a different thread).

The solution is to put a global native reference around "classRawData".
This fixes the problem for me. I'll commit the attached patch unless
there are issues.

2005-03-15 Archie Cobbs <archie@xxxxxxxxxxxx>

* native/jni/java-nio/java_nio_VMDirectByteBuffer.c: use
global native reference to wrap persistent jclass variable.

-Archie

__________________________________________________________________________
Archie Cobbs * CTO, Awarix * http://www.awarix.com
Index: native/jni/java-nio/java_nio_VMDirectByteBuffer.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c,v
retrieving revision 1.2
diff -u -r1.2 java_nio_VMDirectByteBuffer.c
--- native/jni/java-nio/java_nio_VMDirectByteBuffer.c 8 Feb 2005 19:13:03
-0000 1.2
+++ native/jni/java-nio/java_nio_VMDirectByteBuffer.c 16 Mar 2005 04:24:54
-0000
@@ -135,6 +135,14 @@
#else
#error unsupported pointer size
#endif
+
+ /* We need to wrap the jclass in global reference to make it persistent */
+ if ((classRawData = (*env)->NewGlobalRef(env, classRawData)) == NULL)
+ {
+ JCL_ThrowException(env, "java/lang/InternalError",
+ "failed to create global reference");
+ return;
+ }
}

JNIEXPORT jobject JNICALL
_______________________________________________
Classpath-patches mailing list
Classpath-patches@xxxxxxx
http://lists.gnu.org/mailman/listinfo/classpath-patches
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise