mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
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:
@@ -1026,8 +1026,8 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash)
|
|||||||
{
|
{
|
||||||
ssh_key pubkey = NULL;
|
ssh_key pubkey = NULL;
|
||||||
ssh_string pubkey_blob = NULL;
|
ssh_string pubkey_blob = NULL;
|
||||||
MD5CTX ctx;
|
MD5CTX ctx = NULL;
|
||||||
unsigned char *h;
|
unsigned char *h = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (session == NULL || hash == NULL) {
|
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));
|
h = calloc(MD5_DIGEST_LEN, sizeof(unsigned char));
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
|
SSH_STRING_FREE(pubkey_blob);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = md5_init();
|
ctx = md5_init();
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
|
SSH_STRING_FREE(pubkey_blob);
|
||||||
SAFE_FREE(h);
|
SAFE_FREE(h);
|
||||||
return SSH_ERROR;
|
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_data(pubkey_blob),
|
||||||
ssh_string_len(pubkey_blob));
|
ssh_string_len(pubkey_blob));
|
||||||
if (rc != SSH_OK) {
|
if (rc != SSH_OK) {
|
||||||
|
SSH_STRING_FREE(pubkey_blob);
|
||||||
md5_ctx_free(ctx);
|
md5_ctx_free(ctx);
|
||||||
SAFE_FREE(h);
|
SAFE_FREE(h);
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user