diff --git a/owlps-udp-to-http/owlps-udp-to-http.c b/owlps-udp-to-http/owlps-udp-to-http.c index f0aec91..3879726 100644 --- a/owlps-udp-to-http/owlps-udp-to-http.c +++ b/owlps-udp-to-http/owlps-udp-to-http.c @@ -109,11 +109,15 @@ int main(int argc, char *argv[]) ret = receive_udp() ; /* Stop the TCP thread */ + // We must cancel the thread because it can be blocked on the + // recv() call: + if (pthread_cancel(tcp_server_thread)) + perror("Cannot cancel the TCP server thread") ; if (pthread_join(tcp_server_thread, NULL)) perror("Cannot join the TCP server thread") ; - /* Cleaning */ exit: + /* Close sockets */ if (tcp_sockfd >= 0) if (close(tcp_sockfd)) perror("Error closing the TCP socket") ; @@ -121,6 +125,7 @@ int main(int argc, char *argv[]) if (close(udp_sockfd)) perror("Error closing the UDP socket") ; + /* Last cleaning */ free(answer) ; free_results_list() ; sem_destroy(&lock_results) ;