From: Colin Walters Date: Tue, 20 Aug 2024 20:18:54 +0000 (-0400) Subject: lib/traverse: Fix minor memory leak X-Git-Tag: archive/raspbian/2024.8-1+rpi1^2~7^2^2~8^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bd5b4adccdbca18dccd308035412a6ad4972d4d4;p=ostree.git lib/traverse: Fix minor memory leak I was trying to check something with `-fsanitize=address` and it warned about this memory leak. It's...subtle, basically we were leaking when the same commit was added to the hash table. But unfortunately fixing that then complicates ownership over the return value; what we really want to use here is `g_hash_table_steal_all_keys` but RHEL 9.4 is still rocking `glib2-2.68.4` so we can't use it. (Rust would mean we wouldn't have leaked anything here in the first place...) Signed-off-by: Colin Walters --- diff --git a/src/libostree/ostree-repo-traverse.c b/src/libostree/ostree-repo-traverse.c index 08172b8c..4ceabd99 100644 --- a/src/libostree/ostree-repo-traverse.c +++ b/src/libostree/ostree-repo-traverse.c @@ -339,11 +339,13 @@ parents_get_commits (GHashTable *parents_ht, GVariant *object, GHashTable *res) char ** ostree_repo_traverse_parents_get_commits (GHashTable *parents, GVariant *object) { - g_autoptr (GHashTable) res = g_hash_table_new (g_str_hash, g_str_equal); + g_autoptr (GHashTable) res = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); parents_get_commits (parents, object, res); - return (char **)g_hash_table_get_keys_as_array (res, NULL); + // TODO: Once we can depend on modern glib 2.76, just use g_hash_table_steal_all_keys + g_autofree char **tmpbuf = (char **)g_hash_table_get_keys_as_array (res, NULL); + return g_strdupv (tmpbuf); } static gboolean traverse_dirtree (OstreeRepo *repo, const char *checksum, GVariant *parent_key,