]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "sd-dhcp-client: use asynchronous_close()"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Oct 2020 12:11:36 +0000 (21:11 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 24 Oct 2020 11:27:37 +0000 (13:27 +0200)
This effectively reverts the commit 22fc2420b2a7220addcee33c2fa17ada44d87f9c.

The function `asynchronous_close()` confuses valgrind. Before this commit,
valgrind may report the following:

```
HEAP SUMMARY:
    in use at exit: 384 bytes in 1 blocks
  total heap usage: 4,787 allocs, 4,786 frees, 1,379,191 bytes allocated

384 bytes in 1 blocks are possibly lost in loss record 1 of 1
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
   by 0x401456A: _dl_allocate_tls (in /usr/lib64/ld-2.31.so)
   by 0x4BD212E: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.31.so)
   by 0x499B662: asynchronous_job (async.c:47)
   by 0x499B7DC: asynchronous_close (async.c:102)
   by 0x4CFA8B: client_initialize (sd-dhcp-client.c:696)
   by 0x4CFC5E: client_stop (sd-dhcp-client.c:725)
   by 0x4D4589: sd_dhcp_client_stop (sd-dhcp-client.c:2134)
   by 0x493C2F: link_stop_clients (networkd-link.c:620)
   by 0x4126DB: manager_free (networkd-manager.c:867)
   by 0x40D193: manager_freep (networkd-manager.h:97)
   by 0x40DAFC: run (networkd.c:20)

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 384 bytes in 1 blocks
   still reachable: 0 bytes in 0 blocks
        suppressed: 0 bytes in 0 blocks

For lists of detected and suppressed errors, rerun with: -s
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```

src/libsystemd-network/sd-dhcp-client.c

index 53c43508749a7e472644799e3f4b1c5c079e01ef..2bfe64a81c4c083640e6e08e5ecc91843809f183 100644 (file)
 #include "sd-dhcp-client.h"
 
 #include "alloc-util.h"
-#include "async.h"
 #include "dhcp-identifier.h"
 #include "dhcp-internal.h"
 #include "dhcp-lease-internal.h"
 #include "dhcp-protocol.h"
 #include "dns-domain.h"
 #include "event-util.h"
+#include "fd-util.h"
 #include "hostname-util.h"
 #include "io-util.h"
 #include "memory-util.h"
@@ -681,7 +681,7 @@ static int client_initialize(sd_dhcp_client *client) {
 
         client->receive_message = sd_event_source_unref(client->receive_message);
 
-        client->fd = asynchronous_close(client->fd);
+        client->fd = safe_close(client->fd);
 
         (void) event_source_disable(client->timeout_resend);
         (void) event_source_disable(client->timeout_t1);
@@ -1426,7 +1426,7 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
         assert(client);
 
         client->receive_message = sd_event_source_unref(client->receive_message);
-        client->fd = asynchronous_close(client->fd);
+        client->fd = safe_close(client->fd);
 
         client->state = DHCP_STATE_REBINDING;
         client->attempt = 0;
@@ -1783,7 +1783,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
                         (void) event_source_disable(client->timeout_resend);
                         client->receive_message =
                                 sd_event_source_unref(client->receive_message);
-                        client->fd = asynchronous_close(client->fd);
+                        client->fd = safe_close(client->fd);
 
                         if (IN_SET(client->state, DHCP_STATE_REQUESTING,
                                    DHCP_STATE_REBOOTING))