diff --git a/source/6LoWPAN/Thread/thread_dhcpv6_client.c b/source/6LoWPAN/Thread/thread_dhcpv6_client.c index a49054e3ed06..68ae6f433021 100644 --- a/source/6LoWPAN/Thread/thread_dhcpv6_client.c +++ b/source/6LoWPAN/Thread/thread_dhcpv6_client.c @@ -190,16 +190,19 @@ int thread_dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[st } srv_data_ptr = libdhcvp6_nontemporalAddress_server_data_allocate(interface, dhcp_client.libDhcp_instance, mac64, DHCPV6_DUID_HARDWARE_EUI64_TYPE, prefix, dhcp_addr); + if (!srv_data_ptr) { + tr_error("OOM srv_data_ptr"); + return -1; + } payload_len = libdhcpv6_solication_message_length(DHCPV6_DUID_HARDWARE_EUI64_TYPE, true, 0); payload_ptr = ns_dyn_mem_temporary_alloc(payload_len); - - if (payload_ptr == NULL || srv_data_ptr == NULL) { - ns_dyn_mem_free(payload_ptr); + if (!payload_ptr) { libdhcvp6_nontemporalAddress_server_data_free(srv_data_ptr); - tr_error("Out of memory"); + tr_error("OOM payload_ptr"); return -1; } + dhcp_client.global_address_cb = error_cb; //TODO Only supporting one instance globaly if we need more for different instances needs code. srv_data_ptr->GlobalAddress = true; // Build solicit @@ -214,7 +217,13 @@ int thread_dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[st // send solicit srv_data_ptr->transActionId = dhcp_service_send_req(dhcp_client.service_instance, 0, srv_data_ptr , dhcp_addr, payload_ptr, payload_len, dhcp_solicit_resp_cb); - return srv_data_ptr->transActionId ? 0 : -1; + if (srv_data_ptr->transActionId == 0) { + ns_dyn_mem_free(payload_ptr); + libdhcvp6_nontemporalAddress_server_data_free(srv_data_ptr); + return -1; + } + + return 0; } void thread_dhcp_client_global_address_renew(int8_t interface) diff --git a/source/libDHCPv6/dhcp_service_api.c b/source/libDHCPv6/dhcp_service_api.c index 3027046fcc8b..1adb7fa7a5fd 100644 --- a/source/libDHCPv6/dhcp_service_api.c +++ b/source/libDHCPv6/dhcp_service_api.c @@ -458,7 +458,7 @@ uint32_t dhcp_service_send_req(uint16_t instance_id, uint8_t options, void *ptr, msg_tr_ptr = dhcp_tr_create(); if (msg_tr_ptr == NULL || srv_ptr == NULL || msg_ptr == NULL || receive_resp_cb == NULL || msg_len < 5) { - tr_error("request sending failed"); + tr_error("Request sending failed"); return 0; }