gutils: avoid race setting prgname from g_option_context_parse()/g_application_run()

g_option_context_parse()/g_application_run()/g_test_init() for
convenience also call g_set_prgname(), when the prgname is unset at this
point. This was racy.

Fix the race by using an atomic compare-and-exchange and only reset the
value, if it is unset still.
This commit is contained in:
Thomas Haller
2023-11-08 08:48:35 +01:00
parent 54e0b2d75b
commit 7098250e7a
7 changed files with 33 additions and 7 deletions

View File

@@ -38,6 +38,7 @@
#include "gioenumtypes.h"
#include "gioenums.h"
#include "gfile.h"
#include "glib-private.h"
#include "glibintl.h"
#include "gmarshal-internal.h"
@@ -2526,7 +2527,7 @@ g_application_run (GApplication *application,
gchar *prgname;
prgname = g_path_get_basename (argv[0]);
g_set_prgname (prgname);
GLIB_PRIVATE_CALL (g_set_prgname_once) (prgname);
g_free (prgname);
}