Skip to content

Commit

Permalink
Fix memory leak if dhcp renew send fails (ARMmbed#1858)
Browse files Browse the repository at this point in the history
If dhcp_service_send_req() returns failure during renew, previously allocated
payload was not freed. Added check for return value and free for payload if
request sending is failed.
  • Loading branch information
Tero Heinonen authored Oct 11, 2018
1 parent cbf99e7 commit 2ec9b6e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/6LoWPAN/Thread/thread_dhcpv6_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void thread_dhcpv6_renew(protocol_interface_info_entry_t *interface, if_address_
payload_len = libdhcpv6_address_request_message_len(srv_data_ptr->clientLinkIdType, srv_data_ptr->serverLinkType, 0);
payload_ptr = ns_dyn_mem_temporary_alloc(payload_len);
if (payload_ptr == NULL) {
addr->state_timer = 200;//Retry after? should there be maximum 20 second retry
addr->state_timer = 200; //Retry after 20 seconds
tr_error("Out of memory");
return ;
}
Expand All @@ -308,6 +308,11 @@ void thread_dhcpv6_renew(protocol_interface_info_entry_t *interface, if_address_
libdhcpv6_generic_nontemporal_address_message_write(payload_ptr, &packetReq, &nonTemporalAddress, &serverLink);
// send solicit
srv_data_ptr->transActionId = dhcp_service_send_req(dhcp_client.service_instance, 0, srv_data_ptr, srv_data_ptr->server_address, payload_ptr, payload_len, dhcp_solicit_resp_cb);
if (srv_data_ptr->transActionId == 0) {
ns_dyn_mem_free(payload_ptr);
addr->state_timer = 200; //Retry after 20 seconds
tr_error("DHCP renew send failed");
}
}

void thread_dhcpv6_client_set_address(int8_t interface_id, dhcpv6_client_server_data_t *srv_data_ptr)
Expand Down

0 comments on commit 2ec9b6e

Please sign in to comment.