1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
From: Philip Withnall <pwithnall@gnome.org>
Date: Fri, 19 Sep 2025 13:25:53 +0100
Subject: gutils: Fix deliberate-leak code in
g_reload_user_special_dirs_cache()
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
It seems it wasn’t behaving as advertised: it was freeing all the old
string values unless they were strcmp-equal to the new ones, in which
case the new ones were discarded.
What’s actually documented is that the old values are always leaked,
unless they’re strcmp-equal to the new ones.
Adjust the code to match the documentation. A unit test will be added in
a following commit.
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Origin: upstream, 2.86.1, commit:ab09a3e933cb15572a101c7b7cf30e7810342130
---
glib/gutils.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/glib/gutils.c b/glib/gutils.c
index 541ad4a..4d19ddb 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -2337,18 +2337,18 @@ g_reload_user_special_dirs_cache (void)
for (i = 0; i < G_USER_N_DIRECTORIES; i++)
{
old_val = old_g_user_special_dirs[i];
- if (g_user_special_dirs[i] == NULL)
+
+ if (g_user_special_dirs[i] == NULL ||
+ g_strcmp0 (old_val, g_user_special_dirs[i]) != 0)
{
- g_user_special_dirs[i] = old_val;
+ g_ignore_leak (old_val);
}
- else if (g_strcmp0 (old_val, g_user_special_dirs[i]) == 0)
+ else
{
/* don't leak */
g_free (g_user_special_dirs[i]);
g_user_special_dirs[i] = old_val;
}
- else
- g_free (old_val);
}
/* free the old array */
|