From 283d75802d419694dcec3dae95c0c8b6a64d33bf Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 20 Dec 2023 09:43:18 +0100 Subject: [PATCH] session: Avoid memory leaks Thanks coverity CID 1531417 Signed-off-by: Jakub Jelen Reviewed-by: Norbert Pocs --- src/session.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/session.c b/src/session.c index 6b87fe46..58b879ac 100644 --- a/src/session.c +++ b/src/session.c @@ -1026,8 +1026,8 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) { ssh_key pubkey = NULL; ssh_string pubkey_blob = NULL; - MD5CTX ctx; - unsigned char *h; + MD5CTX ctx = NULL; + unsigned char *h = NULL; int rc; if (session == NULL || hash == NULL) { @@ -1064,11 +1064,13 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) h = calloc(MD5_DIGEST_LEN, sizeof(unsigned char)); if (h == NULL) { + SSH_STRING_FREE(pubkey_blob); return SSH_ERROR; } ctx = md5_init(); if (ctx == NULL) { + SSH_STRING_FREE(pubkey_blob); SAFE_FREE(h); return SSH_ERROR; } @@ -1077,6 +1079,7 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) ssh_string_data(pubkey_blob), ssh_string_len(pubkey_blob)); if (rc != SSH_OK) { + SSH_STRING_FREE(pubkey_blob); md5_ctx_free(ctx); SAFE_FREE(h); return rc;