summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-04-27 12:52:29 +0100
committerMatt Caswell <matt@openssl.org>2016-04-28 13:13:09 +0100
commitb0b6ba2d11ce4188e32be50c9e87672c67183616 (patch)
treeb8b7f74b568e9355acce4bb4aa5932015cda0caa
parentdf0f2759220f825efe1a77eae9e658fe37cc89c3 (diff)
Don't leak memory on failure to create a mem BIO
During construction of a mem BIO we allocate some resources. If this allocation fails we can end up leaking everything we have allocated so far. Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r--crypto/bio/bss_mem.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c
index 46bd0343d5..3b6f1734ad 100644
--- a/crypto/bio/bss_mem.c
+++ b/crypto/bio/bss_mem.c
@@ -150,17 +150,22 @@ static int mem_init(BIO *bi, unsigned long flags)
BIO_BUF_MEM *bb = OPENSSL_zalloc(sizeof(*bb));
if (bb == NULL)
- return(0);
- if ((bb->buf = BUF_MEM_new_ex(flags)) == NULL)
- return(0);
- if ((bb->readp = OPENSSL_zalloc(sizeof(*bb->readp))) == NULL)
- return(0);
+ return 0;
+ if ((bb->buf = BUF_MEM_new_ex(flags)) == NULL) {
+ OPENSSL_free(bb);
+ return 0;
+ }
+ if ((bb->readp = OPENSSL_zalloc(sizeof(*bb->readp))) == NULL) {
+ BUF_MEM_free(bb->buf);
+ OPENSSL_free(bb);
+ return 0;
+ }
*bb->readp = *bb->buf;
bi->shutdown = 1;
bi->init = 1;
bi->num = -1;
bi->ptr = (char *)bb;
- return(1);
+ return 1;
}
static int mem_new(BIO *bi)