提交 b0b6ba2d 编写于 作者: M Matt Caswell

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: NRichard Levitte <levitte@openssl.org>
上级 df0f2759
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册