From ebec9c341b97afa01ceab7853599a0c4198ea412 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 25 Jul 2016 14:05:17 -0400 Subject: [PATCH] Inline bio_set. It's only called in one place. The comment about stack-allocated BIOs no longer applies. Change-Id: I5a3cec30bcb46bf1ee2bffd6117485383520b314 Reviewed-on: https://boringssl-review.googlesource.com/8902 Commit-Queue: David Benjamin Reviewed-by: Adam Langley Commit-Queue: Adam Langley CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/bio/bio.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/crypto/bio/bio.c b/crypto/bio/bio.c index 7a1a9e3b..6f112c1a 100644 --- a/crypto/bio/bio.c +++ b/crypto/bio/bio.c @@ -68,25 +68,6 @@ #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. */ -static int bio_set(BIO *bio, const BIO_METHOD *method) { - /* This function can be called with a stack allocated |BIO| so we have to - * assume that the contents of |BIO| are arbitary. This also means that it'll - * leak memory if you call |BIO_set| twice on the same BIO. */ - memset(bio, 0, sizeof(BIO)); - - bio->method = method; - bio->shutdown = 1; - bio->references = 1; - - if (method->create != NULL && !method->create(bio)) { - return 0; - } - - return 1; -} - BIO *BIO_new(const BIO_METHOD *method) { BIO *ret = OPENSSL_malloc(sizeof(BIO)); if (ret == NULL) { @@ -94,9 +75,14 @@ BIO *BIO_new(const BIO_METHOD *method) { return NULL; } - if (!bio_set(ret, method)) { + memset(ret, 0, sizeof(BIO)); + ret->method = method; + ret->shutdown = 1; + ret->references = 1; + + if (method->create != NULL && !method->create(ret)) { OPENSSL_free(ret); - ret = NULL; + return NULL; } return ret;