From 35d337834b86197b6dc0d5c7b1a2c98258e7c827 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Mon, 11 Aug 2025 12:11:44 +0200 Subject: [PATCH] options: Avoid memory leaks on allocation failures When allocation during tilde expansion fails, libssh could leak a memory. Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index 1f849b64..4c65a89d 100644 --- a/src/options.c +++ b/src/options.c @@ -1985,10 +1985,10 @@ int ssh_options_apply(ssh_session session) * it with ssh expansion of ssh escape characters. */ tmp = ssh_path_expand_escape(session, id); + free(id); if (tmp == NULL) { return -1; } - free(id); } /* 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); } if (rc != SSH_OK) { + free(tmp); return -1; } } @@ -2010,13 +2011,14 @@ int ssh_options_apply(ssh_session session) char *id = tmp; tmp = ssh_path_expand_escape(session, id); + free(id); if (tmp == NULL) { return -1; } - free(id); rc = ssh_list_append(session->opts.certificate, tmp); if (rc != SSH_OK) { + free(tmp); return -1; } }