Fix memory leak if setup fails.
[openssl.git] / crypto / cms / cms_enc.c
index 85ae928a496ff09633da8e9ff2870879ae357b80..b14b4b68b5c9508821fe5d2f9dbbf490924ea1a5 100644 (file)
@@ -195,7 +195,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
     ok = 1;
 
  err:
-    if (ec->key && !keep_key) {
+    if (ec->key && (!keep_key || !ok)) {
         OPENSSL_cleanse(ec->key, ec->keylen);
         OPENSSL_free(ec->key);
         ec->key = NULL;