diff --git a/lib/hx509/crypto.c b/lib/hx509/crypto.c index 4b22e4873..b6dc0077a 100644 --- a/lib/hx509/crypto.c +++ b/lib/hx509/crypto.c @@ -1443,6 +1443,7 @@ hx509_crypto_set_key_data(hx509_crypto crypto, const void *data, size_t length) if (crypto->key.data) { free(crypto->key.data); + crypto->key.data = NULL; crypto->key.length = 0; } crypto->key.data = malloc(length); @@ -1470,6 +1471,7 @@ hx509_crypto_set_random_key(hx509_crypto crypto, heim_octet_string *key) } if (RAND_bytes(crypto->key.data, crypto->key.length) <= 0) { free(crypto->key.data); + crypto->key.data = NULL; crypto->key.length = 0; return HX509_CRYPTO_INTERNAL_ERROR; }