-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null pointer dereference (Android + JNI) #39
Comments
As a workaround, you can call once in each thread created from C++: scapix::link::java::attach_current_thread(); For convenience, I can also add generic version of this function (which will do nothing with other bridge languages): scapix::init_thread(); I can also add optional automatic thread attachment: target_compile_definitions(scapix PUBLIC SCAPIX_JNI_AUTO_ATTACH_THREAD) I want to make it optional because it would add slight runtime overhead on each JNI call. What do you think? |
Hi, |
Commit: 0256e3f |
Released in cmodule v1.0.35: |
Great, thanks a lot. |
Hello,
At first, it's not a high priority issue in my opinion, but I found that Scapix may crash at:
Probably 'scope::local' and 'scope::weak' variants are also vulnerable to this issue.
When crash occurred I saw that 'jobject h' was nullptr, so 'NewLocalRef' caused abort with 'null pointer dereference' info. This issue may appear eg. when you store lambda with captured std::function to std::function (Scapix function stored here) and next you copy this std::function on another thread. I think that it may be relatated to detached JNI environment on another thread. I don't know if Scapix do some check like this one:
if (pVM->GetEnv((void**)&mEnvironment, JNI_VERSION_1_6) == JNI_EDETACHED && pVM->AttachCurrentThread(&mEnvironment, nullptr) == JNI_OK)
but if not it may be source of problem. However this issue may be relative easy solved by just store std::shared_ptr with std::function, so copy operate just on std::pointer instead of std::function, thats why I think that priority of this issue isn't high.
Best regards,
Patryk
The text was updated successfully, but these errors were encountered: