Move a declaration that's private to libcrypto
[openssl.git] / crypto / ec / ec_kmeth.c
index fad74bf435b701271812e017989f3c9c367b1ae4..003421eabe8e350db5029550a7fe0c32d7b1c7af 100644 (file)
@@ -53,9 +53,7 @@
 
 #include <string.h>
 #include <openssl/ec.h>
-#ifndef OPENSSL_NO_ENGINE
-# include <openssl/engine.h>
-#endif
+#include <openssl/engine.h>
 #include <openssl/err.h>
 #include "ec_lcl.h"
 
@@ -122,18 +120,28 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
 
     if (ret == NULL) {
         ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);
-        return (NULL);
+        return NULL;
     }
     if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {
         OPENSSL_free(ret);
         return NULL;
     }
 
+    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;
+    }
+
     ret->meth = EC_KEY_get_default_method();
 #ifndef OPENSSL_NO_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;
         }
@@ -145,6 +153,8 @@ EC_KEY *EC_KEY_new_method(ENGINE *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;
         }
@@ -154,6 +164,7 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
     ret->version = 1;
     ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
     ret->references = 1;
+
     if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
         EC_KEY_free(ret);
         return NULL;