From dd23441938d1eb749f734777c292188585fc0b5e Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Mon, 15 Jul 2024 21:00:39 +0200 Subject: [PATCH] agent: Avoid memory leak when handling ssh keys. * agent/command-ssh.c (ssh_send_available_keys): Close file and directory on error paths. -- GnuPG-bug-id: 7201 Signed-off-by: Jakub Jelen --- agent/command-ssh.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agent/command-ssh.c b/agent/command-ssh.c index 02f069dea..47c546bdc 100644 --- a/agent/command-ssh.c +++ b/agent/command-ssh.c @@ -2602,6 +2602,7 @@ ssh_send_available_keys (ctrl_t ctrl, estream_t key_blobs, u32 *r_key_counter) if (!dirname) { err = gpg_error_from_syserror (); + ssh_close_control_file (cf); agent_card_free_keyinfo (keyinfo_on_cards); return err; } @@ -2610,6 +2611,7 @@ ssh_send_available_keys (ctrl_t ctrl, estream_t key_blobs, u32 *r_key_counter) { err = gpg_error_from_syserror (); xfree (dirname); + ssh_close_control_file (cf); agent_card_free_keyinfo (keyinfo_on_cards); return err; } @@ -2714,6 +2716,8 @@ ssh_send_available_keys (ctrl_t ctrl, estream_t key_blobs, u32 *r_key_counter) err = add_to_key_array (&keyarray, key_public, cardsn, order); if (err) { + gnupg_closedir (dir); + ssh_close_control_file (cf); gcry_sexp_release (key_public); xfree (cardsn); goto leave;