mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +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").
|
* 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
|
* Returns: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by
|
||||||
* that must not be modified or freed.
|
* 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
|
* Since: 2.58
|
||||||
*/
|
*/
|
||||||
const gchar * const *
|
const gchar * const *
|
||||||
g_get_language_names_with_category (const gchar *category_name)
|
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);
|
GHashTable *cache = g_private_get (&cache_private);
|
||||||
const gchar *languages;
|
const gchar *languages;
|
||||||
GLanguageNamesCache *name_cache;
|
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
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -67,6 +79,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_bug_base ("http://bugs.gnome.org/");
|
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", 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 ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user