mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 08:50:22 +01:00
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.
This commit is contained in:
parent
8200078ec5
commit
8db0319198
1 changed files with 7 additions and 1 deletions
|
|
@ -2675,9 +2675,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue