Merge pull request #591 from maximkulkin/fix-dhcpserver-memory-leak

extras/dhcpserver - Fix memory leak on stop
This commit is contained in:
Ruslan V. Uss 2018-03-13 18:30:27 +05:00 committed by GitHub
commit f296f4d91e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
} }
} }