From e6b18ffaea7d557eec3028a37c043da67a78550c Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Wed, 26 Aug 2015 12:30:56 +0200 Subject: sd-dhcp: don't randomly ref objects In our API design, getter-functions don't ref objects. Calls like foo_get_bar() will not ref 'bar'. We never do that and there is no real reason to do it in single threaded APIs. If you need a ref-count, you better take it yourself *BEFORE* doing anything else on the parent object (as this might invalidate your pointer). Right now, sd_dhcp?_get_lease() refs the lease it returns. A lot of code-paths in systemd do not expect this and thus leak the lease reference. Fix this by changing the API to not ref returned objects. --- src/network/networkd-dhcp4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/network/networkd-dhcp4.c') diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 6288644a1a..1b2ff7c769 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -365,7 +365,7 @@ static int dhcp_lease_renew(sd_dhcp_client *client, Link *link) { sd_dhcp_lease_unref(link->dhcp_lease); link->dhcp4_configured = false; - link->dhcp_lease = lease; + link->dhcp_lease = sd_dhcp_lease_ref(lease); r = sd_dhcp_lease_get_address(lease, &address); if (r < 0) { @@ -454,7 +454,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) { "PREFIXLEN=%u", prefixlen, NULL); - link->dhcp_lease = lease; + link->dhcp_lease = sd_dhcp_lease_ref(lease); if (link->network->dhcp_mtu) { uint16_t mtu; -- cgit v1.2.3-54-g00ecf