diff options
author | Benjamin Gilbert <bgilbert@backtick.net> | 2015-04-26 00:53:09 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2016-03-26 08:52:40 -0400 |
commit | 41888493f04bfcc42d5287267708edcc49d7b4ea (patch) | |
tree | 959a122d078226627f02cd700f0588673e5b9ba0 | |
parent | f55a5b69b7d8af8872bf785810db8fa8cd7bf905 (diff) | |
download | glib-41888493f04bfcc42d5287267708edcc49d7b4ea.tar.gz |
Fix thread safety of g_get_language_names()
https://bugzilla.gnome.org/show_bug.cgi?id=748474
-rw-r--r-- | glib/gcharset.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/glib/gcharset.c b/glib/gcharset.c index 0a4b0daa3..d47541cba 100644 --- a/glib/gcharset.c +++ b/glib/gcharset.c @@ -228,17 +228,14 @@ g_get_codeset (void) #ifndef G_OS_WIN32 -static GHashTable *alias_table = NULL; - /* read an alias file for the locales */ static void -read_aliases (gchar *file) +read_aliases (gchar *file, + GHashTable *alias_table) { FILE *fp; char buf[256]; - if (!alias_table) - alias_table = g_hash_table_new (g_str_hash, g_str_equal); fp = fopen (file,"r"); if (!fp) return; @@ -289,11 +286,16 @@ static char * unalias_lang (char *lang) { #ifndef G_OS_WIN32 + static GHashTable *alias_table = NULL; char *p; int i; - if (!alias_table) - read_aliases ("/usr/share/locale/locale.alias"); + if (g_once_init_enter (&alias_table)) + { + GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal); + read_aliases ("/usr/share/locale/locale.alias", table); + g_once_init_leave (&alias_table, table); + } i = 0; while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0)) |