Call BIO_free() to release bio if ASN1_i2d_bio_of() fails, preventing a memory leak.
Fixes: 6a3579e190 ("CMP: add support for requesting cert template using genm/genp")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27647)
bio, tmpl)) {
CMP_err1("error saving certTemplate from genp: cannot write file %s",
file);
+ BIO_free(bio);
return 0;
} else {
CMP_info1("stored certTemplate from genp to file '%s'", file);
if (!ASN1_i2d_bio_of(OSSL_CMP_ATAVS, i2d_OSSL_CMP_ATAVS, bio, keyspec)) {
CMP_err1("error saving keySpec from genp: cannot write file %s", file);
+ BIO_free(bio);
return 0;
} else {
CMP_info1("stored keySpec from genp to file '%s'", file);