examples/ssh_client: Fix the memory leak in RTOS environment
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I20108753cf0b86e18724171dc7b25790350edb08
Этот коммит содержится в:
родитель
c9e6461546
Коммит
9b7c4307a4
@ -82,7 +82,7 @@ static void add_cmd(char *cmd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds[n] = strdup(cmd);
|
cmds[n] = cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
@ -127,7 +127,7 @@ static int opts(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown option %c\n", optopt);
|
fprintf(stderr, "Unknown option %c\n", optopt);
|
||||||
usage();
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
@ -139,7 +139,7 @@ static int opts(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (host == NULL) {
|
if (host == NULL) {
|
||||||
usage();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -303,8 +303,6 @@ static void batch_shell(ssh_session session)
|
|||||||
|
|
||||||
for (i = 0; i < MAXCMD && cmds[i]; ++i) {
|
for (i = 0; i < MAXCMD && cmds[i]; ++i) {
|
||||||
s += snprintf(buffer + s, sizeof(buffer) - s, "%s ", cmds[i]);
|
s += snprintf(buffer + s, sizeof(buffer) - s, "%s ", cmds[i]);
|
||||||
free(cmds[i]);
|
|
||||||
cmds[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = ssh_channel_new(session);
|
channel = ssh_channel_new(session);
|
||||||
@ -417,13 +415,14 @@ int main(int argc, char **argv)
|
|||||||
ssh_callbacks_init(&cb);
|
ssh_callbacks_init(&cb);
|
||||||
ssh_set_callbacks(session,&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,
|
fprintf(stderr,
|
||||||
"Error parsing command line: %s\n",
|
"Error parsing command line: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
|
ssh_free(session);
|
||||||
|
ssh_finalize();
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
opts(argc, argv);
|
|
||||||
signal(SIGTERM, do_exit);
|
signal(SIGTERM, do_exit);
|
||||||
|
|
||||||
set_pcap(session);
|
set_pcap(session);
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user