From 4a9cfd763eaba36701caa673b433e716b8d2949f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bodo=20M=C3=B6ller?= Date: Fri, 16 Jun 2006 01:01:14 +0000 Subject: [PATCH] Another thread-safety fix --- crypto/bn/bn_mont.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index 153f8d8e00..961ca67ea1 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -407,6 +407,7 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, const BIGNUM *mod, BN_CTX *ctx) { int got_write_lock = 0; + BN_MONT_CTX *ret; CRYPTO_r_lock(lock); if (!*pmont) @@ -417,19 +418,20 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, if (!*pmont) { - BN_MONT_CTX *mtmp; - mtmp = BN_MONT_CTX_new(); - if (mtmp && !BN_MONT_CTX_set(mtmp, mod, ctx)) - BN_MONT_CTX_free(mtmp); + ret = BN_MONT_CTX_new(); + if (ret && !BN_MONT_CTX_set(ret, mod, ctx)) + BN_MONT_CTX_free(ret); else - *pmont = mtmp; + *pmont = ret; } } + ret = *pmont; + if (got_write_lock) CRYPTO_w_unlock(lock); else CRYPTO_r_unlock(lock); - return *pmont; + return ret; } -- 2.40.0