mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
agent: Fix memory leak.
This commit is contained in:
@@ -350,6 +350,7 @@ struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *s
|
|||||||
struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
|
struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
|
||||||
char **comment) {
|
char **comment) {
|
||||||
struct ssh_key_struct *key;
|
struct ssh_key_struct *key;
|
||||||
|
struct ssh_public_key_struct *pkey;
|
||||||
struct ssh_string_struct *blob = NULL;
|
struct ssh_string_struct *blob = NULL;
|
||||||
struct ssh_string_struct *tmp = NULL;
|
struct ssh_string_struct *tmp = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -397,7 +398,10 @@ struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *se
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ssh_pki_convert_key_to_publickey(key);
|
pkey = ssh_pki_convert_key_to_publickey(key);
|
||||||
|
ssh_key_free(key);
|
||||||
|
|
||||||
|
return pkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_string agent_sign_data(struct ssh_session_struct *session,
|
ssh_string agent_sign_data(struct ssh_session_struct *session,
|
||||||
|
20
src/pki.c
20
src/pki.c
@@ -404,21 +404,33 @@ int ssh_pki_import_privkey_file(const char *filename,
|
|||||||
/* temporary function to migrate seemlessly to ssh_key */
|
/* temporary function to migrate seemlessly to ssh_key */
|
||||||
ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key) {
|
ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key) {
|
||||||
ssh_public_key pub;
|
ssh_public_key pub;
|
||||||
|
ssh_key tmp;
|
||||||
|
|
||||||
if(key == NULL) {
|
if(key == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp = ssh_key_dup(key);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pub = malloc(sizeof(struct ssh_public_key_struct));
|
pub = malloc(sizeof(struct ssh_public_key_struct));
|
||||||
if (pub == NULL) {
|
if (pub == NULL) {
|
||||||
|
ssh_key_free(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ZERO_STRUCTP(pub);
|
ZERO_STRUCTP(pub);
|
||||||
|
|
||||||
pub->dsa_pub = key->dsa;
|
pub->type = tmp->type;
|
||||||
pub->rsa_pub = key->rsa;
|
pub->type_c = tmp->type_c;
|
||||||
pub->type = key->type;
|
|
||||||
pub->type_c = key->type_c;
|
pub->dsa_pub = tmp->dsa;
|
||||||
|
tmp->dsa = NULL;
|
||||||
|
pub->rsa_pub = tmp->rsa;
|
||||||
|
tmp->rsa = NULL;
|
||||||
|
|
||||||
|
ssh_key_free(tmp);
|
||||||
|
|
||||||
return pub;
|
return pub;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user