const char **errmsg_p)
{
struct openssh_new_key *key = load_openssh_new_key(filename, errmsg_p);
- struct ssh2_userkey *retkey;
+ struct ssh2_userkey *retkey = NULL;
int i;
struct ssh2_userkey *retval = NULL;
const char *errmsg;
unsigned checkint0, checkint1;
const void *priv, *string;
int privlen, stringlen, key_index;
- const struct ssh_signkey *alg;
+ const struct ssh_signkey *alg = NULL;
blob = NULL;
(const unsigned char *)thiskey);
if (key_index == key->key_wanted) {
retkey = snew(struct ssh2_userkey);
+ retkey->comment = NULL;
retkey->alg = alg;
retkey->data = alg->openssh_createkey(alg, &thiskey, &thiskeylen);
if (!retkey->data) {
- sfree(retkey);
errmsg = "unable to create key data structure";
goto error;
}
errmsg = NULL; /* no error */
retval = retkey;
+ retkey = NULL; /* prevent the free */
error:
if (blob) {
smemclr(blob, blobsize);
sfree(blob);
}
+ if (retkey) {
+ sfree(retkey->comment);
+ if (retkey->data) {
+ assert(alg);
+ alg->freekey(retkey->data);
+ }
+ sfree(retkey);
+ }
smemclr(key->keyblob, key->keyblob_size);
sfree(key->keyblob);
smemclr(key, sizeof(*key));