Merge pull request #591 from maximkulkin/fix-dhcpserver-memory-leak
extras/dhcpserver - Fix memory leak on stop
This commit is contained in:
commit
f296f4d91e
1 changed files with 7 additions and 1 deletions
|
@ -99,6 +99,7 @@ void dhcpserver_start(const ip4_addr_t *first_client_addr, uint8_t max_leases)
|
||||||
dhcpserver_stop();
|
dhcpserver_stop();
|
||||||
|
|
||||||
state = malloc(sizeof(server_state_t));
|
state = malloc(sizeof(server_state_t));
|
||||||
|
memset(state, 0, sizeof(*state));
|
||||||
state->max_leases = max_leases;
|
state->max_leases = max_leases;
|
||||||
state->leases = calloc(max_leases, sizeof(dhcp_lease_t));
|
state->leases = calloc(max_leases, sizeof(dhcp_lease_t));
|
||||||
bzero(state->leases, max_leases * sizeof(dhcp_lease_t));
|
bzero(state->leases, max_leases * sizeof(dhcp_lease_t));
|
||||||
|
@ -116,8 +117,13 @@ void dhcpserver_stop(void)
|
||||||
{
|
{
|
||||||
if (dhcpserver_task_handle) {
|
if (dhcpserver_task_handle) {
|
||||||
vTaskDelete(dhcpserver_task_handle);
|
vTaskDelete(dhcpserver_task_handle);
|
||||||
free(state);
|
|
||||||
dhcpserver_task_handle = NULL;
|
dhcpserver_task_handle = NULL;
|
||||||
|
|
||||||
|
if (state->nc)
|
||||||
|
netconn_delete(state->nc);
|
||||||
|
free(state->leases);
|
||||||
|
free(state);
|
||||||
|
state = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue