session: Avoid memory leaks

Thanks coverity

CID 1531417

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Norbert Pocs <norbertpocs0@gmail.com>
This commit is contained in:
Jakub Jelen
2023-12-20 09:43:18 +01:00
parent 71c47b464a
commit 283d75802d

View File

@@ -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;