diff options
Diffstat (limited to 'crypto/ec/ec_kmeth.c')
-rw-r--r-- | crypto/ec/ec_kmeth.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index fead014ebc..eb469ba3ad 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -78,15 +78,11 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE); return NULL; } - if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) { - OPENSSL_free(ret); - return NULL; - } + ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE); - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data); OPENSSL_free(ret); return NULL; } @@ -96,10 +92,7 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) if (engine != NULL) { if (!ENGINE_init(engine)) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB); - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data); - CRYPTO_THREAD_lock_free(ret->lock); - OPENSSL_free(ret); - return NULL; + goto err; } ret->engine = engine; } else @@ -108,25 +101,27 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) ret->meth = ENGINE_get_EC(ret->engine); if (ret->meth == NULL) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB); - ENGINE_finish(ret->engine); - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data); - CRYPTO_THREAD_lock_free(ret->lock); - OPENSSL_free(ret); - return NULL; + goto err; } } #endif ret->version = 1; ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; - ret->references = 1; + + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) { + goto err; + } if (ret->meth->init != NULL && ret->meth->init(ret) == 0) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_INIT_FAIL); - EC_KEY_free(ret); - return NULL; + goto err; } return ret; + +err: + EC_KEY_free(ret); + return NULL; } int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |