Fix possible race condition.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 11 Nov 2005 12:59:39 +0000 (12:59 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 11 Nov 2005 12:59:39 +0000 (12:59 +0000)
crypto/bn/bn_mont.c

index 82af91f90d7f5ca0660c7761a4caafa20a39b640..42376dae6bdf627d2f5c02f5cb1eeee60e1476db 100644 (file)
@@ -358,12 +358,12 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
        CRYPTO_w_lock(lock);
        if (!*pmont)
                {
-               *pmont = BN_MONT_CTX_new();
-               if (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))
-                       {
-                       BN_MONT_CTX_free(*pmont);
-                       *pmont = NULL;
-                       }
+               BN_MONT_CTX *mtmp;
+               mtmp = BN_MONT_CTX_new();
+               if (mtmp && !BN_MONT_CTX_set(mtmp, mod, ctx))
+                       BN_MONT_CTX_free(mtmp);
+               else
+                       *pmont = mtmp;
                }
        CRYPTO_w_unlock(lock);
        return *pmont;