options: Avoid memory leaks on allocation failures

When allocation during tilde expansion fails, libssh could
leak a memory.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2025-08-11 12:11:44 +02:00
parent ba1e8303f8
commit 35d337834b

View File

@@ -1985,10 +1985,10 @@ int ssh_options_apply(ssh_session session)
* it with ssh expansion of ssh escape characters. * it with ssh expansion of ssh escape characters.
*/ */
tmp = ssh_path_expand_escape(session, id); tmp = ssh_path_expand_escape(session, id);
free(id);
if (tmp == NULL) { if (tmp == NULL) {
return -1; return -1;
} }
free(id);
} }
/* use append to keep the order at first call and use prepend /* use append to keep the order at first call and use prepend
@@ -1999,6 +1999,7 @@ int ssh_options_apply(ssh_session session)
rc = ssh_list_append(session->opts.identity, tmp); rc = ssh_list_append(session->opts.identity, tmp);
} }
if (rc != SSH_OK) { if (rc != SSH_OK) {
free(tmp);
return -1; return -1;
} }
} }
@@ -2010,13 +2011,14 @@ int ssh_options_apply(ssh_session session)
char *id = tmp; char *id = tmp;
tmp = ssh_path_expand_escape(session, id); tmp = ssh_path_expand_escape(session, id);
free(id);
if (tmp == NULL) { if (tmp == NULL) {
return -1; return -1;
} }
free(id);
rc = ssh_list_append(session->opts.certificate, tmp); rc = ssh_list_append(session->opts.certificate, tmp);
if (rc != SSH_OK) { if (rc != SSH_OK) {
free(tmp);
return -1; return -1;
} }
} }