From efa48c1c21e4eadf03e3a4bbd944bd85b00f0898 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 1 Aug 2024 16:47:11 +0200 Subject: [PATCH] dir: Use same mechanism for get_system/user_default_base_dir_location Also add the same missing valgrind suppression for the system dir location. --- common/flatpak-dir.c | 18 +++++++++++------- tests/flatpak.supp | 8 ++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 69597ad1..efb5076a 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -1538,20 +1538,24 @@ flatpak_deploy_new (GFile *dir, GFile * flatpak_get_system_default_base_dir_location (void) { - static gsize path = 0; + static gsize file = 0; - if (g_once_init_enter (&path)) + if (g_once_init_enter (&file)) { gsize setup_value = 0; + const char *path; const char *system_dir = g_getenv ("FLATPAK_SYSTEM_DIR"); - if (system_dir != NULL) - setup_value = (gsize) system_dir; + if (system_dir != NULL && *system_dir != 0) + path = system_dir; else - setup_value = (gsize) FLATPAK_SYSTEMDIR; - g_once_init_leave (&path, setup_value); + path = FLATPAK_SYSTEMDIR; + + setup_value = (gsize) g_file_new_for_path (path); + + g_once_init_leave (&file, setup_value); } - return g_file_new_for_path ((char *) path); + return g_object_ref ((GFile *) file); } static FlatpakDirStorageType diff --git a/tests/flatpak.supp b/tests/flatpak.supp index 6938c626..bc0a6f97 100644 --- a/tests/flatpak.supp +++ b/tests/flatpak.supp @@ -254,6 +254,14 @@ fun:g_file_new_for_path fun:flatpak_get_user_base_dir_location } +# Deliberately leaking once per process +{ + flatpak_get_system_default_base_dir_location + Memcheck:Leak + ... + fun:g_file_new_for_path + fun:flatpak_get_system_default_base_dir_location +} # https://github.com/ostreedev/ostree/issues/2592 {