Make dlerror(3) thread-safe.
I gave up trying to use the usual thread-local buffer idiom; calls to
calloc(3) and free(3) from any of the "dl" functions -- which live in
the dynamic linker -- end up resolving to the dynamic linker's stubs.
I tried to work around that, but was just making things more complicated.
This alternative costs us a well-known TLS slot (instead of the
dynamically-allocated TLS slot we'd have used otherwise, so no difference
there), plus an extra buffer inside every pthread_internal_t.
Bug: 5404023
Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
diff --git a/libc/bionic/strerror.cpp b/libc/bionic/strerror.cpp
index 455dc52..a50c99f 100644
--- a/libc/bionic/strerror.cpp
+++ b/libc/bionic/strerror.cpp
@@ -41,6 +41,6 @@
}
LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, strerror, NL_TEXTMAX);
- strerror_r(error_number, strerror_buffer, strerror_buffer_size);
- return strerror_buffer;
+ strerror_r(error_number, strerror_tls_buffer, strerror_tls_buffer_size);
+ return strerror_tls_buffer;
}