summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-01-30 07:57:28 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2019-02-01 11:36:48 +0100
commite7e458044e3d3a7270b07a3053f9c06bd3b85c65 (patch)
tree53cd5e807c113142be3efe50eb4f86dd1cdca08a
parentf015d3004531813673e1703fe76b743f1b76824a (diff)
downloadNetworkManager-e7e458044e3d3a7270b07a3053f9c06bd3b85c65.tar.gz
libnm/lldp: fix leak and bug in nm_lldp_neighbor_dup()
For one, just reassigning copy->attrs leaks the previous hash table. Fix that. Also, NMLldpNeighbor instances are not immutable. I think that is an uglyness, and it would be preferable that they can be sealed. A sealed object could safely share/ref the internal hash-table. However, as it is, we cannot just have two NMLldpNeighbor instances share the same hash-table. Do a full copy.
-rw-r--r--libnm/nm-device.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index 7d0bf5722a..70a75c8728 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -2685,9 +2685,15 @@ static NMLldpNeighbor *
nm_lldp_neighbor_dup (NMLldpNeighbor *neighbor)
{
NMLldpNeighbor *copy;
+ GHashTableIter iter;
+ const char *key;
+ GVariant *value;
copy = nm_lldp_neighbor_new ();
- copy->attrs = g_hash_table_ref (neighbor->attrs);
+
+ g_hash_table_iter_init (&iter, neighbor->attrs);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
+ g_hash_table_insert (copy->attrs, g_strdup (key), g_variant_ref (value));
return copy;
}