From e38036e670d234b36053e03be92dd8f27acb16c0 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 22 Aug 2024 22:30:25 +0200 Subject: samba: Cleanup jni layer Remember that jni::GlobalRef can be used on multiple threads so we can't store the env, need to call AttachCurrentThread. Fix AttachCurrentThread (g_vm was forgotten). More consistent move and copy constructors in refs. Removed env() method as it would only be valid for Param and Local anyway. --- libs/samba/src/main/cpp/samba.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libs/samba/src/main/cpp/samba.cpp') diff --git a/libs/samba/src/main/cpp/samba.cpp b/libs/samba/src/main/cpp/samba.cpp index 1d1d9d2..1e6b425 100644 --- a/libs/samba/src/main/cpp/samba.cpp +++ b/libs/samba/src/main/cpp/samba.cpp @@ -260,6 +260,12 @@ void RegisterSamba(JNIEnv* env) { g_DirEntryClass = dir_entry_clazz; } +void UnregisterSamba() { + g_CreateDirEntry = 0; + g_NativeSambaClass.reset(); + g_DirEntryClass.reset(); +} + jni::LocalRef CreateDirEntry(JNIEnv* env, const std::string& name, const smb2_stat_64& stat) { auto j_name = jni::UTF8ToString(env, name); // Kotlin size casts Long to ULong @@ -292,3 +298,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { return jni::JNI_VERSION; } + +void JNI_OnUnload(JavaVM *vm, void *reserved) { + // Not called on Android (or in general), but if it where, this would be the place to unregister. + UnregisterSamba(); +} -- cgit v1.2.3-70-g09d2