void params_free(struct init_params *params) { if (params->bind_address != NULL) free(params->bind_address); if (params->bind_port != NULL) free(params->bind_port); if (params->proxy_address != NULL) free(params->proxy_address); if (params->destination_address != NULL) free(params->destination_address); if (params->destination_port != NULL) free(params->destination_port); if (params->packets_send != NULL) packets_free(params->packets_send); if (params->packets_receive != NULL) packets_free(params->packets_receive); if (params->connections != NULL) connections_free(params->connections); if (params->client_buffer != NULL) data_free(params->client_buffer); if (params->libnet != NULL) libnet_destroy(params->libnet); if (params->libpcap != NULL) pcap_close(params->libpcap); free(params); }
void state_free(struct state *state) { /* We have to stop the system call thread first, since it's using * sockets that we want to close and reset. */ syscalls_free(state, state->syscalls); /* Then we close the sockets and reset the connections, while * we still have a netdev for injecting reset packets to free * per-connection kernel state. */ close_all_sockets(state); netdev_free(state->netdev); packets_free(state->packets); code_free(state->code); run_unlock(state); if (pthread_mutex_destroy(&state->mutex) != 0) die_perror("pthread_mutex_destroy"); memset(state, 0, sizeof(*state)); /* paranoia to help catch bugs */ free(state); }