summaryrefslogtreecommitdiffstats
path: root/src/pki.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-22 21:57:00 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-22 21:57:00 +0200
commit8fb8ad01516623976431264f89aed40f274c0787 (patch)
treeea35962c14d5b6b6378457f85a33529d0109df79 /src/pki.c
parent93c4a8e42748ff2c4b67baf8afe497508f20f75e (diff)
downloadlibssh-8fb8ad01516623976431264f89aed40f274c0787.tar.gz
libssh-8fb8ad01516623976431264f89aed40f274c0787.tar.xz
libssh-8fb8ad01516623976431264f89aed40f274c0787.zip
agent: Fix memory leak.
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/pki.c b/src/pki.c
index 3a6e0cf..4be6f58 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -404,21 +404,33 @@ int ssh_pki_import_privkey_file(const char *filename,
/* temporary function to migrate seemlessly to ssh_key */
ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key) {
ssh_public_key pub;
+ ssh_key tmp;
if(key == NULL) {
return NULL;
}
+ tmp = ssh_key_dup(key);
+ if (tmp == NULL) {
+ return NULL;
+ }
+
pub = malloc(sizeof(struct ssh_public_key_struct));
if (pub == NULL) {
+ ssh_key_free(tmp);
return NULL;
}
ZERO_STRUCTP(pub);
- pub->dsa_pub = key->dsa;
- pub->rsa_pub = key->rsa;
- pub->type = key->type;
- pub->type_c = key->type_c;
+ pub->type = tmp->type;
+ pub->type_c = tmp->type_c;
+
+ pub->dsa_pub = tmp->dsa;
+ tmp->dsa = NULL;
+ pub->rsa_pub = tmp->rsa;
+ tmp->rsa = NULL;
+
+ ssh_key_free(tmp);
return pub;
}