diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-04-21 07:19:24 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-04-21 07:19:24 +0000 |
commit | 9db82bfe663b34edf555beea1ec078e7076674b9 (patch) | |
tree | e228a00130bdada5c95b26a492fd1fd589a45850 /libjava/jni | |
parent | 84951de9182fb845ff4648d110b6d8b8d0cd0cd0 (diff) | |
download | gcc-9db82bfe663b34edf555beea1ec078e7076674b9.tar.gz |
2004-04-21 Mark Wielaard <mark@klomp.org>
* native/jni/gtk-peer/gthread-jni.c (maybe_rethrow): Explicitly
malloc and free buf.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@80948 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/jni')
-rw-r--r-- | libjava/jni/gtk-peer/gthread-jni.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/libjava/jni/gtk-peer/gthread-jni.c b/libjava/jni/gtk-peer/gthread-jni.c index cd37fe105af..b21a80c8843 100644 --- a/libjava/jni/gtk-peer/gthread-jni.c +++ b/libjava/jni/gtk-peer/gthread-jni.c @@ -91,28 +91,40 @@ JavaVM *gdk_vm; static void maybe_rethrow(JNIEnv *gdk_env, char *message, char *file, int line) { jthrowable cause; - /* rethrow if an exception happened */ - if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL) { jstring jmessage; - jclass obj_class; + jclass obj_class; jobject obj; jmethodID ctor; - - /* allocate local message in Java */ - int len = strlen(message) + strlen(file) + 25; - char buf[ len ]; - bzero(buf, len); - sprintf(buf, "%s (at %s:%d)", message, file, line); - jmessage = (*gdk_env)->NewStringUTF(gdk_env, buf); + int len; + char *buf; + + /* rethrow if an exception happened */ + if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL) + { + + /* 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 */ - obj_class = (*gdk_env)->FindClass (gdk_env, "java/lang/RuntimeException"); - ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>", "(Ljava/langString;Ljava/lang/Throwable)V"); - obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause); - - /* throw it */ - (*gdk_env)->Throw(gdk_env, (jthrowable)obj); - } + /* create RuntimeException wrapper object */ + obj_class = (*gdk_env)->FindClass (gdk_env, + "java/lang/RuntimeException"); + ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>", + "(Ljava/langString;Ljava/lang/Throwable)V"); + obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause); + + /* throw it */ + (*gdk_env)->Throw(gdk_env, (jthrowable)obj); + } } /* This macro is used to include a source location in the exception message */ |