From f05b42e6df432838f571a73fd917e1117c4c59a7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Sep 2015 11:53:00 +0200 Subject: [PATCH] dhcp/systemd: fix leaking leases after dhcp_lease_load() Fixes: d2dd3b2c90221fdfa40ca81a9fcffe6a777d95de (cherry picked from commit 9e52613612fe9d885389931b22e93301574dd590) --- src/dhcp-manager/nm-dhcp-systemd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-systemd.c b/src/dhcp-manager/nm-dhcp-systemd.c index 2bd0d72ffc..c42ec9508d 100644 --- a/src/dhcp-manager/nm-dhcp-systemd.c +++ b/src/dhcp-manager/nm-dhcp-systemd.c @@ -393,10 +393,11 @@ nm_dhcp_systemd_get_lease_ip_configs (const char *iface, path = get_leasefile_path (iface, uuid, FALSE); r = sd_dhcp_lease_load (&lease, path); - if (r == 0 && lease) { + if (r == 0) { ip4_config = lease_to_ip4_config (lease, NULL, default_route_metric, FALSE, NULL); if (ip4_config) leases = g_slist_append (leases, ip4_config); + sd_dhcp_lease_unref (lease); } return leases; @@ -532,6 +533,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last struct in_addr last_addr = { 0 }; const char *hostname; int r, i; + gboolean success = FALSE; g_assert (priv->client4 == NULL); g_assert (priv->client6 == NULL); @@ -618,8 +620,6 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last } } - if (lease) - sd_dhcp_lease_unref (lease); /* Add requested options */ for (i = 0; dhcp4_requests[i].name; i++) { @@ -642,12 +642,13 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last goto error; } - return TRUE; + success = TRUE; error: - sd_dhcp_client_unref (priv->client4); - priv->client4 = NULL; - return FALSE; + sd_dhcp_lease_unref (lease); + if (!success) + priv->client4 = sd_dhcp_client_unref (priv->client4); + return success; } static void