sd-dhcp-client: do not crash if sd_dhcp_client_send_release() is called with no lease

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-10-02 10:29:41 +02:00
parent 8ff4585ffa
commit 8bea7e700f
2 changed files with 4 additions and 3 deletions

View file

@ -1895,6 +1895,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
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;

View file

@ -864,10 +864,10 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
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);