Avoid using goto in Nettle crypto wrapper.

This commit is contained in:
Milan Broz
2021-02-12 12:00:55 +01:00
parent 4309294c2a
commit c72030d25a

View File

@@ -301,12 +301,16 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
h->hash = _get_alg(name);
if (!h->hash)
goto bad;
if (!h->hash) {
free(h);
return -EINVAL;
}
h->key = malloc(key_length);
if (!h->key)
goto bad;
if (!h->key) {
free(h);
return -ENOMEM;
}
memcpy(h->key, key, key_length);
h->key_length = key_length;
@@ -316,9 +320,6 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
*ctx = h;
return 0;
bad:
free(h);
return -EINVAL;
}
static void crypt_hmac_restart(struct crypt_hmac *ctx)