From b97704dee60071b2df68858a59d57dbcc26efcaf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 14 Feb 2024 23:59:46 +0000 Subject: [PATCH] dir: Don't store a pointer in a gsize This is, strictly speaking, not allowed. On uncommon architectures like CHERI, a pointer can be larger than a gsize. This might also help to avoid AddressSanitizer losing track of reachability, so that it won't think the array and its contents have been leaked. Signed-off-by: Simon McVittie --- common/flatpak-dir.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index e9fe0764..dbac2dc1 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -1842,16 +1842,16 @@ GPtrArray * flatpak_get_system_base_dir_locations (GCancellable *cancellable, GError **error) { - static gsize array = 0; + static gsize initialized = 0; + static GPtrArray *array = NULL; - if (g_once_init_enter (&array)) + if (g_once_init_enter (&initialized)) { - gsize setup_value = 0; - setup_value = (gsize) get_system_locations (cancellable, error); - g_once_init_leave (&array, setup_value); + array = get_system_locations (cancellable, error); + g_once_init_leave (&initialized, 1); } - return (GPtrArray *) array; + return array; } GFile *