From 725eeb4af14c6fec4ed26a796cdfd6d50df86d42 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 14 May 2020 17:56:25 -0300 Subject: string: Use tls-internal on strerror_l The buffer allocation uses the same strategy of strsignal. Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, and s390x-linux-gnu. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- string/strerror_l.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'string') diff --git a/string/strerror_l.c b/string/strerror_l.c index 017bd14b99..a203e9e80b 100644 --- a/string/strerror_l.c +++ b/string/strerror_l.c @@ -18,11 +18,8 @@ #include #include #include -#include #include -#include - -static __thread char *last_value; +#include static const char * @@ -43,12 +40,13 @@ __strerror_l (int errnum, locale_t loc) char *err = (char *) __get_errlist (errnum); if (__glibc_unlikely (err == NULL)) { - free (last_value); - if (__asprintf (&last_value, "%s%d", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%d", translate ("Unknown error ", loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - err = last_value; + err = tls_internal->strerror_l_buf; } else err = (char *) translate (err, loc); @@ -58,10 +56,3 @@ __strerror_l (int errnum, locale_t loc) } weak_alias (__strerror_l, strerror_l) libc_hidden_def (__strerror_l) - -void -__strerror_thread_freeres (void) -{ - free (last_value); -} -text_set_element (__libc_subfreeres, __strerror_thread_freeres); -- cgit 1.4.1