Revert "bio: remove reference count."

Android uses BIO reference counting.

This reverts commit 9bde6aeb76.

Change-Id: Ibf4a7f42477549d10829a424ea3b52f09098666c
Reviewed-on: https://boringssl-review.googlesource.com/4472
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Adam Langley 2015-04-20 15:25:21 -07:00
parent a91fd063cf
commit ab9017b0ff
2 changed files with 7 additions and 0 deletions

View File

@ -75,6 +75,7 @@ static int bio_set(BIO *bio, const BIO_METHOD *method) {
bio->method = method; bio->method = method;
bio->shutdown = 1; bio->shutdown = 1;
bio->references = 1;
if (method->create != NULL && !method->create(bio)) { if (method->create != NULL && !method->create(bio)) {
return 0; return 0;
@ -102,6 +103,11 @@ int BIO_free(BIO *bio) {
BIO *next_bio; BIO *next_bio;
for (; bio != NULL; bio = next_bio) { for (; bio != NULL; bio = next_bio) {
int refs = CRYPTO_add(&bio->references, -1, CRYPTO_LOCK_BIO);
if (refs > 0) {
return 0;
}
if (bio->callback != NULL) { if (bio->callback != NULL) {
int i = (int)bio->callback(bio, BIO_CB_FREE, NULL, 0, 0, 1); int i = (int)bio->callback(bio, BIO_CB_FREE, NULL, 0, 0, 1);
if (i <= 0) { if (i <= 0) {

View File

@ -781,6 +781,7 @@ struct bio_st {
/* num is a BIO-specific value. For example, in fd BIOs it's used to store a /* num is a BIO-specific value. For example, in fd BIOs it's used to store a
* file descriptor. */ * file descriptor. */
int num; int num;
int references;
void *ptr; void *ptr;
/* next_bio points to the next |BIO| in a chain. This |BIO| owns a reference /* next_bio points to the next |BIO| in a chain. This |BIO| owns a reference
* to |next_bio|. */ * to |next_bio|. */