summaryrefslogtreecommitdiffstats
path: root/src/crypto/bio/bio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bio/bio.c')
-rw-r--r--src/crypto/bio/bio.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/crypto/bio/bio.c b/src/crypto/bio/bio.c
index 694a11c..5ac5911 100644
--- a/src/crypto/bio/bio.c
+++ b/src/crypto/bio/bio.c
@@ -65,6 +65,8 @@
#include <openssl/mem.h>
#include <openssl/thread.h>
+#include "../internal.h"
+
/* BIO_set initialises a BIO structure to have the given type and sets the
* reference count to one. It returns one on success or zero on error. */
@@ -104,8 +106,7 @@ int BIO_free(BIO *bio) {
BIO *next_bio;
for (; bio != NULL; bio = next_bio) {
- int refs = CRYPTO_add(&bio->references, -1, CRYPTO_LOCK_BIO);
- if (refs > 0) {
+ if (!CRYPTO_refcount_dec_and_test_zero(&bio->references)) {
return 0;
}
@@ -128,7 +129,7 @@ int BIO_free(BIO *bio) {
}
BIO *BIO_up_ref(BIO *bio) {
- CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO);
+ CRYPTO_refcount_inc(&bio->references);
return bio;
}
@@ -507,7 +508,7 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
done += n;
if (len < max_len && len - done < kChunkSize / 2) {
len += kChunkSize;
- if (len > max_len) {
+ if (len < kChunkSize || len > max_len) {
len = max_len;
}
uint8_t *new_buf = OPENSSL_realloc(*out, len);