GH1537: Avoid double-free in the EVP_PKEY API
authorAlex Gaynor <alex.gaynor@gmail.com>
Wed, 7 Sep 2016 13:41:20 +0000 (09:41 -0400)
committerRich Salz <rsalz@openssl.org>
Wed, 7 Sep 2016 13:42:50 +0000 (09:42 -0400)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit d65c3615f6c658478503f4862f8055203a98038c)

crypto/evp/p_lib.c

index a4dcf581c7bbfcefb1239ab69bc87b1cd1f460dd..9828620552bef6c7dd0fb9fdba246a284074740a 100644 (file)
@@ -398,6 +398,7 @@ void EVP_PKEY_free(EVP_PKEY *x)
         return;
     REF_ASSERT_ISNT(i < 0);
     EVP_PKEY_free_it(x);
+    CRYPTO_THREAD_lock_free(x->lock);
     sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
     OPENSSL_free(x);
 }
@@ -413,7 +414,6 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
     ENGINE_finish(x->engine);
     x->engine = NULL;
 #endif
-    CRYPTO_THREAD_lock_free(x->lock);
 }
 
 static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,