summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2019-07-08 15:00:16 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-07-08 17:26:21 +0200
commit0734bc490fe51b9d93180b77a418f2969fe80f06 (patch)
tree1c6c182bd424d419375e18dc9ee88f2e0b23365a
parentb275045ac8ea66397546ac00a44149c927130914 (diff)
downloadlibssh-0734bc490fe51b9d93180b77a418f2969fe80f06.tar.gz
libssh-0734bc490fe51b9d93180b77a418f2969fe80f06.tar.xz
libssh-0734bc490fe51b9d93180b77a418f2969fe80f06.zip
examples: Fix freeing the channel in ssh_client
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
-rw-r--r--examples/ssh_client.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/examples/ssh_client.c b/examples/ssh_client.c
index 1860da3f..54ecd30b 100644
--- a/examples/ssh_client.c
+++ b/examples/ssh_client.c
@@ -239,7 +239,6 @@ static void select_loop(ssh_session session,ssh_channel channel)
ssh_connector_free(connector_err);
ssh_event_free(event);
- ssh_channel_free(channel);
}
static void shell(ssh_session session)
@@ -247,7 +246,11 @@ static void shell(ssh_session session)
ssh_channel channel;
struct termios terminal_local;
int interactive=isatty(0);
+
channel = ssh_channel_new(session);
+ if (channel == NULL) {
+ return;
+ }
if (interactive) {
tcgetattr(0, &terminal_local);
@@ -256,6 +259,7 @@ static void shell(ssh_session session)
if (ssh_channel_open_session(channel)) {
printf("Error opening channel : %s\n", ssh_get_error(session));
+ ssh_channel_free(channel);
return;
}
chan = channel;
@@ -266,6 +270,7 @@ static void shell(ssh_session session)
if (ssh_channel_request_shell(channel)) {
printf("Requesting shell : %s\n", ssh_get_error(session));
+ ssh_channel_free(channel);
return;
}
@@ -279,6 +284,7 @@ static void shell(ssh_session session)
if (interactive) {
do_cleanup(0);
}
+ ssh_channel_free(channel);
}
static void batch_shell(ssh_session session)
@@ -295,12 +301,18 @@ static void batch_shell(ssh_session session)
}
channel = ssh_channel_new(session);
+ if (channel == NULL) {
+ return;
+ }
+
ssh_channel_open_session(channel);
if (ssh_channel_request_exec(channel, buffer)) {
printf("Error executing '%s' : %s\n", buffer, ssh_get_error(session));
+ ssh_channel_free(channel);
return;
}
select_loop(session, channel);
+ ssh_channel_free(channel);
}
static int client(ssh_session session)