From b51566ad3f8a4a28e7478171c5e23517bd2b4c62 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 27 Jul 2020 17:32:16 +0200 Subject: ssh: Various connection closing fixes --- ssh/client_proxy.c | 6 +++--- ssh/sshnc.c | 2 ++ ssh/tomsg_clientlib.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'ssh') diff --git a/ssh/client_proxy.c b/ssh/client_proxy.c index 1ce5e12..369ed0a 100644 --- a/ssh/client_proxy.c +++ b/ssh/client_proxy.c @@ -51,14 +51,14 @@ static void* proxy_thread_entry(void *thread_data_) { struct thread_data *thread_data = thread_data_; int client_sock = thread_data->client_sock; - struct sshnc_client *client; + struct sshnc_client *client = NULL; enum sshnc_retval ret = sshnc_connect( thread_data->server_host, thread_data->server_port, "tomsg", "tomsg", hostkey_checker, NULL, &client); if (ret != SSHNC_OK) { fprintf(stderr, "Could not connect over SSH: %s\n", sshnc_strerror(ret)); - return NULL; + goto cleanup; } struct pollfd polls[2]; @@ -137,7 +137,7 @@ static void* proxy_thread_entry(void *thread_data_) { cleanup: close(client_sock); - sshnc_close(client); + if (client) sshnc_close(client); return NULL; } diff --git a/ssh/sshnc.c b/ssh/sshnc.c index 872be2a..7d42de8 100644 --- a/ssh/sshnc.c +++ b/ssh/sshnc.c @@ -142,6 +142,8 @@ enum sshnc_retval sshnc_connect( void *userdata, struct sshnc_client **clientp // output ) { + *clientp = NULL; + clear_additional_error(); const ssh_session session = ssh_new(); diff --git a/ssh/tomsg_clientlib.c b/ssh/tomsg_clientlib.c index cf02208..c14d5c5 100644 --- a/ssh/tomsg_clientlib.c +++ b/ssh/tomsg_clientlib.c @@ -364,7 +364,7 @@ send_error_return: byte = sendret; writeall(thread_w, &byte, 1); free_client: - sshnc_close(conn); + if (conn) sshnc_close(conn); if (client) { if (client->buffer) free(client->buffer); if (client->inflight) free(client->inflight); -- cgit v1.2.3-70-g09d2