diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index a7a071387..5d35523f2 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -79,10 +79,10 @@ class LibraryNamespaces { std::lock_guard guard(mutex_); - auto it = FindNamespaceByClassLoader(env, class_loader); + android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader); - if (it != namespaces_.end()) { - return it->second; + if (ns != nullptr) { + return ns; } uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED; @@ -90,14 +90,13 @@ class LibraryNamespaces { namespace_type |= ANDROID_NAMESPACE_TYPE_SHARED; } - android_namespace_t* ns = - android_create_namespace("classloader-namespace", - nullptr, - library_path.c_str(), - namespace_type, - java_permitted_path != nullptr ? - permitted_path.c_str() : - nullptr); + ns = android_create_namespace("classloader-namespace", + nullptr, + library_path.c_str(), + namespace_type, + java_permitted_path != nullptr ? + permitted_path.c_str() : + nullptr); namespaces_.push_back(std::make_pair(env->NewWeakGlobalRef(class_loader), ns)); @@ -122,12 +121,12 @@ class LibraryNamespaces { return initialized_; } - std::vector>::const_iterator - FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { - return std::find_if(namespaces_.begin(), namespaces_.end(), - [&](const std::pair& value) { - return env->IsSameObject(value.first, class_loader); - }); + android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { + auto it = std::find_if(namespaces_.begin(), namespaces_.end(), + [&](const std::pair& value) { + return env->IsSameObject(value.first, class_loader); + }); + return it != namespaces_.end() ? it->second : nullptr; } bool initialized_;