aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Xiao <xiaoxiang@xiaomi.com>2021-05-06 23:16:56 -0700
committerJakub Jelen <jjelen@redhat.com>2021-05-12 16:01:18 +0200
commit9b7c4307a4abccaf7fde8233de9d34daed5714f6 (patch)
tree643e426b3701c8037cd999427bea3ea1d749e5b1
parentc9e64615460e589c49516229da5134bd97522337 (diff)
downloadlibssh-master.tar.gz
libssh-master.tar.xz
libssh-master.zip
examples/ssh_client: Fix the memory leak in RTOS environmentHEADmaster
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I20108753cf0b86e18724171dc7b25790350edb08
-rw-r--r--examples/ssh_client.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/ssh_client.c b/examples/ssh_client.c
index 1fe6031d..ec137436 100644
--- a/examples/ssh_client.c
+++ b/examples/ssh_client.c
@@ -82,7 +82,7 @@ static void add_cmd(char *cmd)
return;
}
- cmds[n] = strdup(cmd);
+ cmds[n] = cmd;
}
static void usage(void)
@@ -127,7 +127,7 @@ static int opts(int argc, char **argv)
#endif
default:
fprintf(stderr, "Unknown option %c\n", optopt);
- usage();
+ return -1;
}
}
if (optind < argc) {
@@ -139,7 +139,7 @@ static int opts(int argc, char **argv)
}
if (host == NULL) {
- usage();
+ return -1;
}
return 0;
@@ -303,8 +303,6 @@ static void batch_shell(ssh_session session)
for (i = 0; i < MAXCMD && cmds[i]; ++i) {
s += snprintf(buffer + s, sizeof(buffer) - s, "%s ", cmds[i]);
- free(cmds[i]);
- cmds[i] = NULL;
}
channel = ssh_channel_new(session);
@@ -417,13 +415,14 @@ int main(int argc, char **argv)
ssh_callbacks_init(&cb);
ssh_set_callbacks(session,&cb);
- if (ssh_options_getopt(session, &argc, argv)) {
+ if (ssh_options_getopt(session, &argc, argv) || opts(argc, argv)) {
fprintf(stderr,
"Error parsing command line: %s\n",
ssh_get_error(session));
+ ssh_free(session);
+ ssh_finalize();
usage();
}
- opts(argc, argv);
signal(SIGTERM, do_exit);
set_pcap(session);