开发者

JNI_CreateJavaVM: Buffer overrun if I throw an exception in case of failure

In a C++ project, I use the JNI invocation API to launch a JVM. I've done a little wrapper arount the JVM so I can use all the needed parts in a OO fashion. So far that works great.

Now开发者_Python百科, if the JVM does not start (JNI_CreateJavaVM returns a value < 0) I'd like to raise an exception within my C++ code.But if I throw an exception after JNI_CreateJavaVM, I get a buffer overrun. If I raise the exception without the JNI_CreateJavaVM call, it works as expected.

Does anyone have a clue on what the issue could be here? Or how to debug this?

Environment: Windows, Visual Studio 2008 JDK: jrockit27.6jdk16005, but happens with SUN stock one as well

Cheers Dominik


Looks to me like you are throwing a pointer or reference to an invalid memory. It's a good idea to throw an exception by reference, but make sure that the object is not on the stack. If the object was allocated using 'new', you'll need to manage this properly (otherwise you'll have leaks). My approach is to try and throw const objects as much as possible.

Does this help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜