aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ec/ec_kmeth.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-07-02 17:19:17 +1000
committerPauli <pauli@openssl.org>2023-07-05 08:34:00 +1000
commit97beb77f319f119957235233396627bb22283da0 (patch)
treee2c58f0b0e46f90ca732da86e9a315a781622ed9 /crypto/ec/ec_kmeth.c
parent52c362b3fe5ab9b1c44ec560820b242eb3df0e3b (diff)
downloadopenssl-97beb77f319f119957235233396627bb22283da0.tar.gz
fix memory allocation and reference counting issues
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Kurt Roeckx <kurt@roeckx.be> (Merged from https://github.com/openssl/openssl/pull/21341)
Diffstat (limited to 'crypto/ec/ec_kmeth.c')
-rw-r--r--crypto/ec/ec_kmeth.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c
index ec68ab154e..3471a82d7c 100644
--- a/crypto/ec/ec_kmeth.c
+++ b/crypto/ec/ec_kmeth.c
@@ -86,6 +86,11 @@ EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
if (ret == NULL)
return NULL;
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
+ OPENSSL_free(ret);
+ return NULL;
+ }
+
ret->libctx = libctx;
if (propq != NULL) {
ret->propq = OPENSSL_strdup(propq);
@@ -93,9 +98,6 @@ EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
goto err;
}
- if (!CRYPTO_NEW_REF(&ret->references, 1))
- goto err;
-
ret->meth = EC_KEY_get_default_method();
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
if (engine != NULL) {
@@ -133,7 +135,6 @@ EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
return ret;
err:
- CRYPTO_FREE_REF(&ret->references);
EC_KEY_free(ret);
return NULL;
}