Merge pull request #81 from kiwix/fix_local_ref

Do not keep localRef to object once it is added to an array.
This commit is contained in:
Matthieu Gautier 2024-02-05 11:18:04 +01:00 committed by GitHub
commit 843e628348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 0 deletions

View File

@ -95,6 +95,7 @@ METHOD0(jobjectArray, getIllustrations) {
for (auto illu: illustrations) {
auto wrapper = BUILD_WRAPPER("org/kiwix/libkiwix/Illustration", illu);
env->SetObjectArrayElement(retArray, index++, wrapper);
env->DeleteLocalRef(wrapper);
}
return retArray;
} CATCH_EXCEPTION(nullptr)

View File

@ -104,6 +104,7 @@ METHOD(jobjectArray, getBookmarks, jboolean onlyValidBookmarks) {
shared_ptr<kiwix::Bookmark>* handle = new shared_ptr<kiwix::Bookmark>(new kiwix::Bookmark(std::move(bookmark)));
jobject wrapper = env->NewObject(wrapperClass, initMethod, reinterpret_cast<jlong>(handle));
env->SetObjectArrayElement(retArray, index++, wrapper);
env->DeleteLocalRef(wrapper);
}
return retArray;
} CATCH_EXCEPTION(nullptr)

View File

@ -263,6 +263,7 @@ template<> struct JTypeArray<std::string>{
for(size_t index=0; index<length; index++) {
auto jElem = c2jni(data[index], env);
env->SetObjectArrayElement(array, index, jElem);
env->DeleteLocalRef(jElem);
}
}
};