Add error_msg argument to CloseNativeLibrary
error_msg is set when dlclose/NativeBridgeUnloadLibrary fails.
Bug: https://issuetracker.google.com/79126103
Test: make
Change-Id: I043580209538ff47320e8d9a304a21c00c4b149f
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 67c1c10..b3e2b97 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -710,9 +710,21 @@
#endif
}
-bool CloseNativeLibrary(void* handle, const bool needs_native_bridge) {
- return needs_native_bridge ? NativeBridgeUnloadLibrary(handle) :
- dlclose(handle);
+bool CloseNativeLibrary(void* handle, const bool needs_native_bridge, std::string* error_msg) {
+ bool success;
+ if (needs_native_bridge) {
+ success = (NativeBridgeUnloadLibrary(handle) == 0);
+ if (!success) {
+ *error_msg = NativeBridgeGetError();
+ }
+ } else {
+ success = (dlclose(handle) == 0);
+ if (!success) {
+ *error_msg = dlerror();
+ }
+ }
+
+ return success;
}
#if defined(__ANDROID__)