public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andreas Schwab <schwab@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] duplocale: protect use of global locale (bug 23970) Date: Mon, 11 Mar 2024 09:01:50 +0000 (GMT) [thread overview] Message-ID: <20240311090150.73B42385840D@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=513331b788a3fa633f1d0417d43915e16a0c88f0 commit 513331b788a3fa633f1d0417d43915e16a0c88f0 Author: Andreas Schwab <schwab@suse.de> Date: Wed Mar 6 12:59:47 2024 +0100 duplocale: protect use of global locale (bug 23970) Protect the global locale from being modified while we compute the size of the locale category names. That allows the use of the global locale in a single thread, while all other threads use the thread safe locale functions. Diff: --- locale/duplocale.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/locale/duplocale.c b/locale/duplocale.c index a755ac5c36..bad476700f 100644 --- a/locale/duplocale.c +++ b/locale/duplocale.c @@ -43,6 +43,11 @@ __duplocale (locale_t dataset) int cnt; size_t names_len = 0; + /* If dataset points to _nl_global_locale, we need to prevent other + threads from modifying it. We also modify global data below (the + usage counts). */ + __libc_rwlock_wrlock (__libc_setlocale_lock); + /* Calculate the total space we need to store all the names. */ for (cnt = 0; cnt < __LC_LAST; ++cnt) if (cnt != LC_ALL && dataset->__names[cnt] != _nl_C_name) @@ -55,9 +60,6 @@ __duplocale (locale_t dataset) { char *namep = (char *) (result + 1); - /* We modify global data (the usage counts). */ - __libc_rwlock_wrlock (__libc_setlocale_lock); - for (cnt = 0; cnt < __LC_LAST; ++cnt) if (cnt != LC_ALL) { @@ -78,11 +80,11 @@ __duplocale (locale_t dataset) result->__ctype_b = dataset->__ctype_b; result->__ctype_tolower = dataset->__ctype_tolower; result->__ctype_toupper = dataset->__ctype_toupper; - - /* It's done. */ - __libc_rwlock_unlock (__libc_setlocale_lock); } + /* It's done. */ + __libc_rwlock_unlock (__libc_setlocale_lock); + return result; } weak_alias (__duplocale, duplocale)
reply other threads:[~2024-03-11 9:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240311090150.73B42385840D@sourceware.org \ --to=schwab@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).