libnm: fix memory leak when parsing IP configuration

When the dictionary contains keys "address" and "uri", the first value
is leaked.

  ==4730== 14 bytes in 1 blocks are definitely lost in loss record 51 of 1,755
  ==4730==    at 0x4841866: malloc (vg_replace_malloc.c:446)
  ==4730==    by 0x4CC5CB9: g_malloc (gmem.c:100)
  ==4730==    by 0x4CDF518: g_strdup (gstrfuncs.c:323)
  ==4730==    by 0x496A6B8: g_strdup_inline (gstrfuncs.h:321)
  ==4730==    by 0x496A6B8: nm_inet_ntop_dup (nm-inet-utils.h:355)
  ==4730==    by 0x496A95B: nm_inet_parse_str (nm-inet-utils.c:539)
  ==4730==    by 0x48AF3A3: _notify_update_prop_nameservers (nm-ip-config.c:179)

Fixes: 4422b14704 ('core, libnm: support per-connection DNS URIs')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2184
(cherry picked from commit 37d8945b13)
This commit is contained in:
Beniamino Galvani 2025-04-08 08:41:52 +02:00
parent 59be16b91a
commit 2172c5ff5a

View file

@ -180,6 +180,7 @@ _notify_update_prop_nameservers(NMClient *client,
goto next;
nameserver = g_steal_pointer(&val_str);
} else if (nm_streq(key, "uri")) {
g_free(nameserver);
nameserver = g_variant_dup_string(val, NULL);
}
next: