]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp: don't randomly ref objects
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 26 Aug 2015 10:30:56 +0000 (12:30 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Wed, 26 Aug 2015 10:30:56 +0000 (12:30 +0200)
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/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/test-dhcp-client.c
src/network/networkd-dhcp4.c

index 6a0d270739df4cef7951aaa46b8c8547e18c5ea3..46104afdedaa6d4d15661ccb6d75a646d36e4768 100644 (file)
@@ -348,7 +348,7 @@ int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
             client->state != DHCP_STATE_REBINDING)
                 return -EADDRNOTAVAIL;
 
-        *ret = sd_dhcp_lease_ref(client->lease);
+        *ret = client->lease;
 
         return 0;
 }
index bc17c6adc504c83c24e3423e71f333d6e4d8e911..10c3654020bf47280434ab971362b89285fb496d 100644 (file)
@@ -260,7 +260,7 @@ int sd_dhcp6_client_get_lease(sd_dhcp6_client *client, sd_dhcp6_lease **ret) {
         if (!client->lease)
                 return -ENOMSG;
 
-        *ret = sd_dhcp6_lease_ref(client->lease);
+        *ret = client->lease;
 
         return 0;
 }
index d341210887c43f6d7e99cbef26e4cca392a5a95a..200499d613bfccc193eea28f224246351e03ddd9 100644 (file)
@@ -393,7 +393,6 @@ static void test_addr_acq_acquired(sd_dhcp_client *client, int event,
         if (verbose)
                 printf("  DHCP address acquired\n");
 
-        sd_dhcp_lease_unref(lease);
         sd_event_exit(e, 0);
 }
 
index 6288644a1a3a6cb2a7b7ecc69581790f4be720e9..1b2ff7c76976562142408222753445c939f7d76a 100644 (file)
@@ -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;