From: Richard Levitte Date: Thu, 29 Jun 2000 16:32:34 +0000 (+0000) Subject: Make the use of logstream thread-safe. X-Git-Tag: OpenSSL-engine-0_9_6-beta1~38 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=70d03c4f597c416b418954a7f7cb6f7e62c5b5c5;p=oweals%2Fopenssl.git Make the use of logstream thread-safe. --- diff --git a/crypto/engine/hw_ncipher.c b/crypto/engine/hw_ncipher.c index 58c7cb009d..0512262a17 100644 --- a/crypto/engine/hw_ncipher.c +++ b/crypto/engine/hw_ncipher.c @@ -451,7 +451,8 @@ static int hwcrhk_finish() goto err; } err: - logstream = NULL; + if (logstream) + BIO_free(logstream); hwcrhk_dso = NULL; p_hwcrhk_Init = NULL; p_hwcrhk_Finish = NULL; @@ -470,7 +471,15 @@ static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)()) switch(cmd) { case ENGINE_CTRL_SET_LOGSTREAM: - logstream = (BIO *)p; + if (logstream) + { + BIO_free(logstream); + logstream = NULL; + } + if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1) + logstream = (BIO *)p; + else + ENGINEerr(ENGINE_F_HWCRHK_CTRL,ENGINE_R_BIO_WAS_FREED); break; default: ENGINEerr(ENGINE_F_HWCRHK_CTRL, @@ -748,10 +757,15 @@ static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt) static void log_message(void *logstream, const char *message) { BIO *lstream = NULL; + + CRYPTO_w_lock(CRYPTO_LOCK_BIO); if (logstream) lstream=*(BIO **)logstream; if (lstream) + { BIO_write(lstream, message, strlen(message)); + } + CRYPTO_w_unlock(CRYPTO_LOCK_BIO); } #endif /* HW_NCIPHER */