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
This commit is contained in:
Sven Herzberg 2009-10-23 14:49:38 +02:00
parent d105f431b0
commit 3dab24828e

View File

@ -1968,10 +1968,17 @@ g_get_prgname (void)
void void
g_set_prgname (const gchar *prgname) g_set_prgname (const gchar *prgname)
{ {
gboolean already_set = FALSE;
G_LOCK (g_prgname); G_LOCK (g_prgname);
g_free (g_prgname); if (g_prgname)
already_set = TRUE;
else
g_prgname = g_strdup (prgname); g_prgname = g_strdup (prgname);
G_UNLOCK (g_prgname); G_UNLOCK (g_prgname);
if (already_set)
g_warning ("g_set_prgname() called multiple times");
} }
G_LOCK_DEFINE_STATIC (g_application_name); G_LOCK_DEFINE_STATIC (g_application_name);
@ -2038,7 +2045,7 @@ g_set_application_name (const gchar *application_name)
G_UNLOCK (g_application_name); G_UNLOCK (g_application_name);
if (already_set) if (already_set)
g_warning ("g_set_application() name called multiple times"); g_warning ("g_set_application_name() called multiple times");
} }
/** /**