JNI_CreateJavaVM: buffer overflow if I make an exception in case of failure

In a C ++ project, I use the JNI call API to start the JVM. I made a small wrapper for the JVM, so I can use all the necessary parts in OO style. So far, this works great.

Now, if the JVM does not start ( JNI_CreateJavaVM returns <0), I would like to throw an exception in my C ++ code. But if I make an exception after JNI_CreateJavaVM , I will get a buffer overrun. If I throw an exception without calling JNI_CreateJavaVM , it works as expected.

Does anyone know what could be here? Or how to debug this?

Environment: Windows, Visual Studio 2008 JDK: jrockit27.6jdk16005, but also with SUN.

Greetings Dominik

+6
c ++ exception jni
source share
1 answer

It looks like you are throwing a pointer or referring to an invalid memory. It is a good idea to throw an exception by reference, but make sure the object is not on the stack. If the object was selected using the "new", you will need to do it correctly (otherwise you will have leaks). My approach is to try to maximize const objects.

Does it help?

+2
source share

All Articles