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 --- sysdeps/generic/tls-internal-struct.h | 1 + sysdeps/generic/tls-internal.h | 1 + sysdeps/mach/strerror_l.c | 32 +++++++++++--------------------- sysdeps/unix/sysv/linux/tls-internal.h | 1 + 4 files changed, 14 insertions(+), 21 deletions(-) (limited to 'sysdeps') diff --git a/sysdeps/generic/tls-internal-struct.h b/sysdeps/generic/tls-internal-struct.h index 33a9079ee9..156e722bd8 100644 --- a/sysdeps/generic/tls-internal-struct.h +++ b/sysdeps/generic/tls-internal-struct.h @@ -22,6 +22,7 @@ struct tls_internal_t { char *strsignal_buf; + char *strerror_l_buf; }; #endif diff --git a/sysdeps/generic/tls-internal.h b/sysdeps/generic/tls-internal.h index 1f6a117d76..b4b03b4ecf 100644 --- a/sysdeps/generic/tls-internal.h +++ b/sysdeps/generic/tls-internal.h @@ -34,6 +34,7 @@ static inline void __glibc_tls_internal_free (void) { free (__tls_internal.strsignal_buf); + free (__tls_internal.strerror_l_buf); } #endif diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c index b6c9fdbe80..72b857f4a0 100644 --- a/sysdeps/mach/strerror_l.c +++ b/sysdeps/mach/strerror_l.c @@ -23,11 +23,7 @@ #include #include #include -#include -#include - - -static __thread char *last_value; +#include static const char * @@ -58,13 +54,14 @@ __strerror_l (int errnum, locale_t loc) if (system > err_max_system || ! __mach_error_systems[system].bad_sub) { - free (last_value); - if (__asprintf (&last_value, "%s%X", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%X", translate ("Error in unknown error system: ", loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } es = &__mach_error_systems[system]; @@ -74,25 +71,18 @@ __strerror_l (int errnum, locale_t loc) if (code >= es->subsystem[sub].max_code) { - free (last_value); - if (__asprintf (&last_value, "%s%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%s %d", translate ("Unknown error ", loc), translate (es->subsystem[sub].subsys_name, loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } return (char *) translate (es->subsystem[sub].codes[code], loc); } weak_alias (__strerror_l, strerror_l) libc_hidden_def (__strerror_l) - -/* This is called when a thread is exiting to free the last_value string. */ -void -__strerror_thread_freeres (void) -{ - free (last_value); -} -text_set_element (__libc_subfreeres, __strerror_thread_freeres); diff --git a/sysdeps/unix/sysv/linux/tls-internal.h b/sysdeps/unix/sysv/linux/tls-internal.h index 5d712abd4a..d07f4b680d 100644 --- a/sysdeps/unix/sysv/linux/tls-internal.h +++ b/sysdeps/unix/sysv/linux/tls-internal.h @@ -32,6 +32,7 @@ static inline void __glibc_tls_internal_free (void) { free (THREAD_SELF->tls_state.strsignal_buf); + free (THREAD_SELF->tls_state.strerror_l_buf); } #endif -- cgit v1.2.3