mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_netif: Cleanup dhcp-server allocations
This commit is contained in:
parent
1b49cf373f
commit
27375c7917
@ -552,6 +552,11 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
||||
// Create DHCP server structure
|
||||
if (esp_netif_config->base->flags & ESP_NETIF_DHCP_SERVER) {
|
||||
esp_netif->dhcps = dhcps_new();
|
||||
if (esp_netif->dhcps == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create dhcp server handle");
|
||||
esp_netif_destroy(esp_netif);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -111,8 +111,7 @@ static void dhcps_tmr(void* arg);
|
||||
|
||||
dhcps_t *dhcps_new(void)
|
||||
{
|
||||
dhcps_t *dhcps = mem_malloc(sizeof(dhcps_t));
|
||||
memset(dhcps , 0x00 , sizeof(dhcps_t));
|
||||
dhcps_t *dhcps = mem_calloc(1, sizeof(dhcps_t));
|
||||
|
||||
if (dhcps == NULL) {
|
||||
return NULL;
|
||||
@ -126,7 +125,7 @@ dhcps_t *dhcps_new(void)
|
||||
#endif
|
||||
dhcps->plist = NULL;
|
||||
dhcps->renew = false;
|
||||
dhcps->dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
|
||||
dhcps->dhcps_lease_time = DHCPS_LEASE_TIME_DEF;
|
||||
dhcps->dhcps_offer = 0xFF;
|
||||
dhcps->dhcps_dns = 0x00;
|
||||
dhcps->dhcps_pcb = NULL;
|
||||
@ -926,14 +925,12 @@ static s16_t parse_msg(dhcps_t *dhcps, struct dhcps_msg *m, u16_t len)
|
||||
pdhcps_pool = NULL;
|
||||
pnode = NULL;
|
||||
} else {
|
||||
pdhcps_pool = (struct dhcps_pool *)mem_malloc(sizeof(struct dhcps_pool));
|
||||
memset(pdhcps_pool , 0x00 , sizeof(struct dhcps_pool));
|
||||
pdhcps_pool = (struct dhcps_pool *)mem_calloc(1, sizeof(struct dhcps_pool));
|
||||
|
||||
pdhcps_pool->ip.addr = dhcps->client_address.addr;
|
||||
memcpy(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac));
|
||||
pdhcps_pool->lease_timer = lease_timer;
|
||||
pnode = (list_node *)mem_malloc(sizeof(list_node));
|
||||
memset(pnode , 0x00 , sizeof(list_node));
|
||||
pnode = (list_node *)mem_calloc(1, sizeof(list_node));
|
||||
|
||||
pnode->pnode = pdhcps_pool;
|
||||
pnode->pnext = NULL;
|
||||
@ -1033,13 +1030,12 @@ static void handle_dhcp(void *arg,
|
||||
malloc_len = p->tot_len;
|
||||
}
|
||||
|
||||
pmsg_dhcps = (struct dhcps_msg *)mem_malloc(malloc_len);
|
||||
pmsg_dhcps = (struct dhcps_msg *)mem_calloc(1, malloc_len);
|
||||
if (NULL == pmsg_dhcps) {
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(pmsg_dhcps , 0x00 , malloc_len);
|
||||
p_dhcps_msg = (u8_t *)pmsg_dhcps;
|
||||
tlen = p->tot_len;
|
||||
data = p->payload;
|
||||
|
@ -114,6 +114,7 @@ TEST_CASE("localhost ping test", "[lwip]")
|
||||
TEST_CASE("dhcp server init/deinit", "[lwip][leaks=0]")
|
||||
{
|
||||
dhcps_t *dhcps = dhcps_new();
|
||||
TEST_ASSERT_NOT_NULL(dhcps);
|
||||
ip4_addr_t ip = { .addr = IPADDR_ANY };
|
||||
TEST_ASSERT(dhcps_start(dhcps, NULL, ip) == ERR_ARG);
|
||||
TEST_ASSERT(dhcps_stop(dhcps, NULL) == ERR_ARG);
|
||||
|
Loading…
Reference in New Issue
Block a user