aboutsummaryrefslogtreecommitdiff
path: root/intl/dcigettext.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-09-24 16:09:09 +0000
committerUlrich Drepper <drepper@redhat.com>2007-09-24 16:09:09 +0000
commit408cfca0c4ec78358314d9fc7c36448d36eeb931 (patch)
treed0d72b0ff464969b671ab0d84cbe929d1d065f8c /intl/dcigettext.c
parenta389bcaa40376bc0fb1a0958d4d9e5dc2f794e5e (diff)
downloadglibc-408cfca0c4ec78358314d9fc7c36448d36eeb931.zip
glibc-408cfca0c4ec78358314d9fc7c36448d36eeb931.tar.gz
glibc-408cfca0c4ec78358314d9fc7c36448d36eeb931.tar.bz2
[BZ #5058]
2007-09-24 Ulrich Drepper <drepper@redhat.com> [BZ #5058] * intl/gettextP.h (struct loaded_domain): Add conversions_lock member. * intl/loadmsgcat.c (_nl_load_domain): Initialize conversions_lock. (_nl_unload_domain): Finalize conversions_lock. * intl/dcigettext.c (_nl_find_msg): Take conversions_lock before handling table of known conversions. * posix/regcomp.c (lookup_collation_sequence_value): Check that
Diffstat (limited to 'intl/dcigettext.c')
-rw-r--r--intl/dcigettext.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index ad2835f..55dcaab 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -850,6 +850,9 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
/* We are supposed to do a conversion. */
const char *encoding = get_output_charset (domainbinding);
+ /* Protect against reallocation of the table. */
+ __libc_rwlock_rdlock (domain->conversions_lock);
+
/* Search whether a table with converted translations for this
encoding has already been allocated. */
size_t nconversions = domain->nconversions;
@@ -866,8 +869,25 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
}
}
+ __libc_rwlock_unlock (domain->conversions_lock);
+
if (convd == NULL)
{
+ /* We have to allocate a new conversions table. */
+ __libc_rwlock_wrlock (domain->conversions_lock);
+
+ /* Maybe in the meantime somebody added the translation.
+ Recheck. */
+ for (i = nconversions; i > 0; )
+ {
+ i--;
+ if (strcmp (domain->conversions[i].encoding, encoding) == 0)
+ {
+ convd = &domain->conversions[i];
+ goto found_convd;
+ }
+ }
+
/* Allocate a table for the converted translations for this
encoding. */
struct converted_domain *new_conversions =
@@ -876,9 +896,13 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
(nconversions + 1) * sizeof (struct converted_domain));
if (__builtin_expect (new_conversions == NULL, 0))
- /* Nothing we can do, no more memory. We cannot use the
- translation because it might be encoded incorrectly. */
- return (char *) -1;
+ {
+ /* Nothing we can do, no more memory. We cannot use the
+ translation because it might be encoded incorrectly. */
+ unlock_fail:
+ __libc_rwlock_unlock (domain->conversions_lock);
+ return (char *) -1;
+ }
domain->conversions = new_conversions;
@@ -887,7 +911,7 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
if (__builtin_expect (encoding == NULL, 0))
/* Nothing we can do, no more memory. We cannot use the
translation because it might be encoded incorrectly. */
- return (char *) -1;
+ goto unlock_fail;
convd = &new_conversions[nconversions];
convd->encoding = encoding;
@@ -989,6 +1013,9 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
convd->conv_tab = NULL;
/* Here domain->conversions is still == new_conversions. */
domain->nconversions++;
+
+ found_convd:
+ __libc_rwlock_unlock (domain->conversions_lock);
}
if (