Index: third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp |
diff --git a/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp b/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp |
index f9d291a98b2f9f4e3594567e88f2d66f512f3ee3..737488114be09e047009cdb09b7cf6493943cc86 100644 |
--- a/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp |
+++ b/third_party/android_crazy_linker/src/tests/foo_with_static_constructor.cpp |
@@ -7,9 +7,16 @@ |
// like __aeabi_atexit(), which are not normally returned by |
// a call to dlsym(). |
+// Libc is not required to copy strings passed to putenv(). If it does |
+// not then env pointers become invalid when rodata is unmapped on |
+// library unload. To guard against this, putenv() strings are first |
+// strdup()'ed. This is a mild memory leak. |
+ |
#include <stdlib.h> |
+#ifdef __arm__ |
extern "C" void __aeabi_atexit(void*); |
+#endif |
Anton
2014/06/11 15:31:54
Seems like this test maybe ARM specific. Do we nee
|
class A { |
public: |
@@ -17,17 +24,17 @@ class A { |
x_ = rand(); |
const char* env = getenv("TEST_VAR"); |
if (!env || strcmp(env, "INIT")) |
- putenv("TEST_VAR=LOAD_ERROR"); |
+ putenv(strdup("TEST_VAR=LOAD_ERROR")); |
else |
- putenv("TEST_VAR=LOADED"); |
+ putenv(strdup("TEST_VAR=LOADED")); |
} |
~A() { |
const char* env = getenv("TEST_VAR"); |
if (!env || strcmp(env, "LOADED")) |
- putenv("TEST_VAR=UNLOAD_ERROR"); |
+ putenv(strdup("TEST_VAR=UNLOAD_ERROR")); |
else |
- putenv("TEST_VAR=UNLOADED"); |
+ putenv(strdup("TEST_VAR=UNLOADED")); |
} |
int Get() const { return x_; } |