diff --git a/src/x509.c b/src/x509.c index 0780601e4..0bf17ba8e 100644 --- a/src/x509.c +++ b/src/x509.c @@ -14098,7 +14098,8 @@ int wolfSSL_X509_REQ_add1_attr_by_NID(WOLFSSL_X509 *req, } } ret = wolfSSL_sk_push(req->reqAttributes, attr); - if (ret != WOLFSSL_SUCCESS) { + if ((ret != WOLFSSL_SUCCESS) || (req->reqAttributes->type == STACK_TYPE_CIPHER)) { + /* CIPHER type makes a copy */ wolfSSL_X509_ATTRIBUTE_free(attr); } }