chiark / gitweb /
libsystemd-dhcp: don't assert on client_stop()
[elogind.git] / src / libsystemd-dhcp / dhcp-client.c
index 9f7a826211d2a3b79fa54f3a4690f77e0b7ffd15..f6a621102219c395460de96177b05fc9bee4e3ad 100644 (file)
@@ -54,6 +54,7 @@ struct sd_dhcp_client {
         union sockaddr_union link;
         sd_event_source *receive_message;
         uint8_t *req_opts;
+        size_t req_opts_allocated;
         size_t req_opts_size;
         be32_t last_addr;
         struct ether_addr mac_addr;
@@ -115,11 +116,11 @@ int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
                 if (client->req_opts[i] == option)
                         return -EEXIST;
 
-        if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size,
+        if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
                             client->req_opts_size + 1))
                 return -ENOMEM;
 
-        client->req_opts[client->req_opts_size - 1] = option;
+        client->req_opts[client->req_opts_size++] = option;
 
         return 0;
 }
@@ -259,8 +260,6 @@ static int client_notify(sd_dhcp_client *client, int event)
 static int client_stop(sd_dhcp_client *client, int error)
 {
         assert_return(client, -EINVAL);
-        assert_return(client->state != DHCP_STATE_INIT &&
-                      client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
 
         client->receive_message =
                 sd_event_source_unref(client->receive_message);