options: Avoid memory leaks during modification of argv
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
2e7ca3e8a6
Коммит
3d0ecd37fe
@ -1255,8 +1255,6 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
char optv[3] = "- ";
|
|
||||||
optv[1] = optopt;
|
|
||||||
tmp = realloc(save, (current + 1) * sizeof(char*));
|
tmp = realloc(save, (current + 1) * sizeof(char*));
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
SAFE_FREE(save);
|
SAFE_FREE(save);
|
||||||
@ -1264,12 +1262,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
save = tmp;
|
save = tmp;
|
||||||
save[current] = strdup(optv);
|
save[current] = argv[optind-1];
|
||||||
if (save[current] == NULL) {
|
|
||||||
SAFE_FREE(save);
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
current++;
|
current++;
|
||||||
/* We can not use optarg here as getopt does not set it for
|
/* We can not use optarg here as getopt does not set it for
|
||||||
* unknown options. We need to manually extract following
|
* unknown options. We need to manually extract following
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user