Fix double-free segmentation fault in concurrent tunnel cleanup

- Remove duplicate remove_tunnel() call in handle_connection cleanup
- Prevent double-free of tunnel resources during concurrent connection cleanup
- Ensure proper thread synchronization during tunnel cleanup
- Fix race condition between forwarding thread exit and cleanup
parent 220bdb98
...@@ -1267,7 +1267,7 @@ cleanup_and_exit: ...@@ -1267,7 +1267,7 @@ cleanup_and_exit:
} }
} }
// Cleanup // Cleanup - close resources and remove from global array
if (new_tunnel) { if (new_tunnel) {
if (new_tunnel->local_sock >= 0) { if (new_tunnel->local_sock >= 0) {
close(new_tunnel->local_sock); close(new_tunnel->local_sock);
...@@ -1275,13 +1275,11 @@ cleanup_and_exit: ...@@ -1275,13 +1275,11 @@ cleanup_and_exit:
if (new_tunnel->ssl) { if (new_tunnel->ssl) {
SSL_free(new_tunnel->ssl); SSL_free(new_tunnel->ssl);
} }
// Remove tunnel from global array
// Remove tunnel from global array and free it
pthread_mutex_lock(&tunnel_mutex); pthread_mutex_lock(&tunnel_mutex);
remove_tunnel(new_tunnel->request_id); remove_tunnel(new_tunnel->request_id);
pthread_mutex_unlock(&tunnel_mutex); pthread_mutex_unlock(&tunnel_mutex);
frame_buffer_free(new_tunnel->incoming_buffer);
free(new_tunnel);
} }
if (config->debug) { if (config->debug) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment