diff options
author | Yann Ylavic <ylavic@apache.org> | 2021-09-12 12:29:39 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2021-09-12 12:29:39 +0000 |
commit | 856763456f65aff83b626d1b433952337ca547ec (patch) | |
tree | ba849da579d5988bc7ae3b5c8740e1c2f9f114db /crypto | |
parent | 6fbacef78f7eaa53d8e709af5a2c3e7a92a364a0 (diff) | |
download | apr-856763456f65aff83b626d1b433952337ca547ec.tar.gz |
apr_crypto_prng: cleanup after ourselves when apr_crypto_prng_init() fails.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1893271 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/apr_crypto_prng.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/crypto/apr_crypto_prng.c b/crypto/apr_crypto_prng.c index 3630a249f..842987f95 100644 --- a/crypto/apr_crypto_prng.c +++ b/crypto/apr_crypto_prng.c @@ -138,6 +138,12 @@ APR_DECLARE(apr_status_t) apr_crypto_prng_init(apr_pool_t *pool, apr_crypto_t *c return APR_EREINIT; } + cprng_ring = apr_palloc(pool, sizeof(*cprng_ring)); + if (!cprng_ring) { + return APR_ENOMEM; + } + APR_RING_INIT(cprng_ring, apr_crypto_prng_t, link); + if (flags & APR_CRYPTO_PRNG_PER_THREAD) { #if !APR_HAS_THREADS return APR_ENOTIMPL; @@ -150,12 +156,6 @@ APR_DECLARE(apr_status_t) apr_crypto_prng_init(apr_pool_t *pool, apr_crypto_t *c #endif } - cprng_ring = apr_palloc(pool, sizeof(*cprng_ring)); - if (!cprng_ring) { - return APR_ENOMEM; - } - APR_RING_INIT(cprng_ring, apr_crypto_prng_t, link); - #if APR_HAS_THREADS rv = apr_thread_mutex_create(&cprng_ring_mutex, APR_THREAD_MUTEX_DEFAULT, pool); @@ -171,8 +171,17 @@ APR_DECLARE(apr_status_t) apr_crypto_prng_init(apr_pool_t *pool, apr_crypto_t *c flags = (flags | APR_CRYPTO_PRNG_LOCKED) & ~APR_CRYPTO_PRNG_PER_THREAD; #endif - return apr_crypto_prng_create(&cprng_global, crypto, cipher, bufsize, flags, - seed, pool); + rv = apr_crypto_prng_create(&cprng_global, crypto, cipher, bufsize, flags, + seed, pool); + if (rv != APR_SUCCESS) { + if (flags & APR_CRYPTO_PRNG_PER_THREAD) { + apr_threadkey_private_delete(cprng_thread_key); + cprng_thread_key = NULL; + } + return rv; + } + + return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_crypto_prng_term(void) |