Commit 60e957d0 by Mark Wielaard Committed by Michael Koch

gthread-jni.c (maybe_rethrow): Explicitly malloc and free buf.

2004-04-21  Mark Wielaard  <mark@klomp.org>

	* native/jni/gtk-peer/gthread-jni.c (maybe_rethrow): Explicitly
	malloc and free buf.

From-SVN: r80948
parent 27dd18cf
2004-04-21 Mark Wielaard <mark@klomp.org>
* native/jni/gtk-peer/gthread-jni.c (maybe_rethrow): Explicitly
malloc and free buf.
2004-04-21 Dalibor Topic <robilad@kaffe.org> 2004-04-21 Dalibor Topic <robilad@kaffe.org>
* javax/naming/AuthenticationException.java, * javax/naming/AuthenticationException.java,
......
...@@ -91,28 +91,40 @@ JavaVM *gdk_vm; ...@@ -91,28 +91,40 @@ JavaVM *gdk_vm;
static void maybe_rethrow(JNIEnv *gdk_env, char *message, char *file, int line) { static void maybe_rethrow(JNIEnv *gdk_env, char *message, char *file, int line) {
jthrowable cause; jthrowable cause;
/* rethrow if an exception happened */
if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL) {
jstring jmessage; jstring jmessage;
jclass obj_class; jclass obj_class;
jobject obj; jobject obj;
jmethodID ctor; jmethodID ctor;
int len;
/* allocate local message in Java */ char *buf;
int len = strlen(message) + strlen(file) + 25;
char buf[ len ]; /* rethrow if an exception happened */
bzero(buf, len); if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL)
sprintf(buf, "%s (at %s:%d)", message, file, line); {
jmessage = (*gdk_env)->NewStringUTF(gdk_env, buf);
/* allocate local message in Java */
len = strlen(message) + strlen(file) + 25;
buf = (char *) malloc(len);
if (buf != NULL)
{
bzero(buf, len);
sprintf(buf, "%s (at %s:%d)", message, file, line);
jmessage = (*gdk_env)->NewStringUTF(gdk_env, buf);
free(buf);
}
else
jmessage = NULL;
/* create RuntimeException wrapper object */ /* create RuntimeException wrapper object */
obj_class = (*gdk_env)->FindClass (gdk_env, "java/lang/RuntimeException"); obj_class = (*gdk_env)->FindClass (gdk_env,
ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>", "(Ljava/langString;Ljava/lang/Throwable)V"); "java/lang/RuntimeException");
obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause); ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>",
"(Ljava/langString;Ljava/lang/Throwable)V");
/* throw it */ obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause);
(*gdk_env)->Throw(gdk_env, (jthrowable)obj);
} /* throw it */
(*gdk_env)->Throw(gdk_env, (jthrowable)obj);
}
} }
/* This macro is used to include a source location in the exception message */ /* This macro is used to include a source location in the exception message */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment