summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2018-06-27 09:57:41 +0200
committerThomas Haller <thaller@redhat.com>2018-09-14 17:21:00 +0200
commit31bda1b8373c71ecb41d8208aa2bc9c88999d988 (patch)
tree32934434b847fa23f586679002623a5c72efdb7b
parente645aeb12ccefb1fbe18bb33d046ee649de86da0 (diff)
clients: fix memory leak when parsing routes
The new hash table should destroy elements stolen from the hash table returned by nm_utils_parse_variant_attributes(). Fixes: d0949141203f6a546317277ed788ea114d401dd8
-rw-r--r--clients/common/nm-meta-setting-desc.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 8c27779e2..f794c67b2 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -192,11 +192,20 @@ _parse_ip_route (int family,
return NULL;
}
- if (!attrs)
- attrs = g_hash_table_new (nm_str_hash, g_str_equal);
+ if (!attrs) {
+ attrs = g_hash_table_new_full (nm_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) g_variant_unref);
+ }
g_hash_table_iter_init (&iter, tmp_attrs);
while (g_hash_table_iter_next (&iter, (gpointer *) &iter_key, (gpointer *) &iter_value)) {
+
+ /* need to sink the reference, because nm_utils_parse_variant_attributes() returns
+ * floating refs. */
+ g_variant_ref_sink (iter_value);
+
if (!nm_ip_route_attribute_validate (iter_key, iter_value, family, NULL, error)) {
g_prefix_error (error, "%s: ", iter_key);
g_hash_table_unref (tmp_attrs);