From 3dab24828edd8ebfd6d6c8bb20c181fc0d5650a1 Mon Sep 17 00:00:00 2001 From: Sven Herzberg Date: Fri, 23 Oct 2009 14:49:38 +0200 Subject: [PATCH] make sure g_set_prgname() gets called only once * glib/gutils.c: copy the call-once statement from g_set_application_name(); Fixes Bug #563627: g_get_prgname() threadsafety --- glib/gutils.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/glib/gutils.c b/glib/gutils.c index 8b7bfe8a6..b5e9c193a 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1968,10 +1968,17 @@ g_get_prgname (void) void g_set_prgname (const gchar *prgname) { + gboolean already_set = FALSE; + G_LOCK (g_prgname); - g_free (g_prgname); - g_prgname = g_strdup (prgname); + if (g_prgname) + already_set = TRUE; + else + g_prgname = g_strdup (prgname); G_UNLOCK (g_prgname); + + if (already_set) + g_warning ("g_set_prgname() called multiple times"); } G_LOCK_DEFINE_STATIC (g_application_name); @@ -2038,7 +2045,7 @@ g_set_application_name (const gchar *application_name) G_UNLOCK (g_application_name); if (already_set) - g_warning ("g_set_application() name called multiple times"); + g_warning ("g_set_application_name() called multiple times"); } /**