Fix a memory leak in the mem bio
authorCorey Minyard <cminyard@mvista.com>
Mon, 21 Jan 2019 07:47:02 +0000 (17:47 +1000)
committerPauli <paul.dale@oracle.com>
Mon, 21 Jan 2019 07:50:04 +0000 (17:50 +1000)
commit492f70645ca912d82af02b9bc06e9472bf0730a0
tree6b58c5526e48edfd33f2c3f53777b9e8c6743824
parent781378dacaac8357e8df5b3ab5e811962dd72bc2
Fix a memory leak in the mem bio

If you use a BIO and set up your own buffer that is not freed, the
memory bio will leak the BIO_BUF_MEM object it allocates.

The trouble is that the BIO_BUF_MEM is allocated and kept around,
but it is not freed if BIO_NOCLOSE is set.

The freeing of BIO_BUF_MEM was fairly confusing, simplify things
so mem_buf_free only frees the memory buffer and free the BIO_BUF_MEM
in mem_free(), where it should be done.

Alse add a test for a leak in the memory bio
Setting a memory buffer caused a leak.

Signed-off-by: Corey Minyard <minyard@acm.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8051)

(cherry picked from commit c6048af23c577bcf85f15122dd03b65f959c9ecb)
crypto/bio/bss_mem.c
test/bio_memleak_test.c [new file with mode: 0644]
test/build.info
test/recipes/90-test_bio_memleak.t [new file with mode: 0644]