From 83e93876d57cddc4a80caf8abbbb7ce61ca39a67 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Fri, 20 Dec 2024 19:15:21 +0200 Subject: [PATCH] lib: spa-device: fix POD props iteration + key lifetimes Fix memory leaks in bad GValue handling. Unset iterator GValue after use and strdup keys. The keys aren't necessarily static strings (for id-XXXX properties), so have to be dup'd. --- lib/wp/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/wp/device.c b/lib/wp/device.c index b1f79a44..5c2eda06 100644 --- a/lib/wp/device.c +++ b/lib/wp/device.c @@ -357,7 +357,7 @@ append_props (WpSpaPodBuilder *b, WpSpaPod *props, GHashTable *used) g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (props); GValue next = G_VALUE_INIT; - while (wp_iterator_next (it, &next)) { + for (; wp_iterator_next (it, &next); g_value_unset (&next)) { WpSpaPod *p = g_value_get_boxed (&next); const char *key; g_autoptr (WpSpaPod) value = NULL; @@ -370,14 +370,14 @@ append_props (WpSpaPodBuilder *b, WpSpaPod *props, GHashTable *used) wp_spa_pod_builder_add_property (b, key); wp_spa_pod_builder_add_pod (b, value); - g_hash_table_add (used, (gpointer) key); + g_hash_table_add (used, (gpointer) g_strdup (key)); } } static WpSpaPod * merge_props (WpSpaPod *old_props, WpSpaPod *new_props) { - g_autoptr (GHashTable) used = g_hash_table_new (g_str_hash, g_str_equal); + g_autoptr (GHashTable) used = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); g_autoptr (WpSpaPodBuilder) b = wp_spa_pod_builder_new_object ( "Spa:Pod:Object:Param:Props", "Props");