Again, a public function should not crash if called at an inopportune moment.
Also, make sure we don't call the function if we have no lease.
int sd_dhcp_client_send_release(sd_dhcp_client *client) {
assert_return(client, -EINVAL);
assert_return(client->state != DHCP_STATE_STOPPED, -ESTALE);
+ assert_return(client->lease, -EUNATCH);
_cleanup_free_ DHCPPacket *release = NULL;
size_t optoffset, optlen;
return 0;
}
- if (link->network->dhcp_send_release)
- (void) sd_dhcp_client_send_release(client);
-
if (link->dhcp_lease) {
+ if (link->network->dhcp_send_release)
+ (void) sd_dhcp_client_send_release(client);
+
r = dhcp_lease_lost(link);
if (r < 0) {
link_enter_failed(link);