Modify android_dlwarning function to use a callback
The previous implementation of android_dlwarning was not thread-safe
and could return a pointer soon to become invalid in some situations.
This change fixed the problem. I have also removed android_dlwarning
from the dlext.h header file in case we decide to keep
android_dlwarning in the final release.
Bug: http://b/27453994
Change-Id: If6c896a80a17c4be0e18795e617712ad36a106fe
diff --git a/linker/linker_dlwarning.cpp b/linker/linker_dlwarning.cpp
index f4a3daf..cd76533 100644
--- a/linker/linker_dlwarning.cpp
+++ b/linker/linker_dlwarning.cpp
@@ -21,7 +21,6 @@
#include <string>
static std::string current_msg;
-static std::string old_msg;
void add_dlwarning(const char* sopath, const char* message, const char* value) {
if (!current_msg.empty()) {
@@ -38,13 +37,12 @@
// Resets the current one (like dlerror but instead of
// being thread-local it is process-local).
-const char* get_dlwarning() {
+void get_dlwarning(void* obj, void (*f)(void*, const char*)) {
if (current_msg.empty()) {
- return nullptr;
+ f(obj, nullptr);
+ } else {
+ std::string msg = current_msg;
+ current_msg.clear();
+ f(obj, msg.c_str());
}
-
- old_msg = current_msg;
- current_msg.clear();
-
- return old_msg.c_str();
}