mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
Merge branch 'fix-leaking-g_get_language_names_with_category' into 'master'
gcharset: fix leaking g_get_language_names_with_category See merge request GNOME/glib!338
This commit is contained in:
commit
7b5756577f
@ -576,15 +576,16 @@ g_get_language_names (void)
|
||||
*
|
||||
* g_get_language_names() returns g_get_language_names_with_category("LC_MESSAGES").
|
||||
*
|
||||
* Returns: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by GLib
|
||||
* that must not be modified or freed.
|
||||
* Returns: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by
|
||||
* the thread g_get_language_names_with_category was called from.
|
||||
* It must not be modified or freed. It must be copied if planned to be used in another thread.
|
||||
*
|
||||
* Since: 2.58
|
||||
*/
|
||||
const gchar * const *
|
||||
g_get_language_names_with_category (const gchar *category_name)
|
||||
{
|
||||
static GPrivate cache_private = G_PRIVATE_INIT ((void (*)(gpointer)) g_hash_table_remove_all);
|
||||
static GPrivate cache_private = G_PRIVATE_INIT ((void (*)(gpointer)) g_hash_table_unref);
|
||||
GHashTable *cache = g_private_get (&cache_private);
|
||||
const gchar *languages;
|
||||
GLanguageNamesCache *name_cache;
|
||||
|
@ -59,6 +59,18 @@ test_language_names_with_category (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_language_names_with_category_async (void)
|
||||
{
|
||||
g_thread_join (g_thread_new (
|
||||
NULL, (GThreadFunc)g_get_language_names_with_category, "LC_CTYPE"));
|
||||
|
||||
/* g_get_language_names_with_category returns a pointer to a memory
|
||||
which is owned by a thread it has been called from. The thread is dead now,
|
||||
therefore returned pointer can't be used at this stage.
|
||||
*/
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -67,6 +79,7 @@ main (int argc, char *argv[])
|
||||
g_test_bug_base ("http://bugs.gnome.org/");
|
||||
|
||||
g_test_add_func ("/charset/language_names_with_category", test_language_names_with_category);
|
||||
g_test_add_func ("/charset/language_names_with_category_async", test_language_names_with_category_async);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user