Skip to content

Commit

Permalink
Merge pull request #81 from kiwix/fix_local_ref
Browse files Browse the repository at this point in the history
Do not keep localRef to object once it is added to an array.
  • Loading branch information
mgautierfr authored Feb 5, 2024
2 parents 4a8e966 + 3f58dc2 commit 843e628
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/main/cpp/libkiwix/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/cpp/libkiwix/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions lib/src/main/cpp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down

0 comments on commit 843e628

Please sign in to comment.