Fix a memory leak in compression

The function RECORD_LAYER_clear() is supposed to clear the contents of the
RECORD_LAYER structure, but retain certain data such as buffers that are
allocated. Unfortunately one buffer (for compression) got missed and was
inadvertently being wiped, thus causing a memory leak.

In part this is due to the fact that RECORD_LAYER_clear() was reaching
inside SSL3_BUFFERs and SSL3_RECORDs, which it really shouldn't. So, I've
rewritten it to only clear the data it knows about, and to defer clearing
of SSL3_RECORD and SSL3_BUFFER structures to SSL_RECORD_clear() and the
new function SSL3_BUFFER_clear().

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Matt Caswell
2015-05-21 14:06:52 +01:00
parent 3a752c85ee
commit 6b41b3f5ea
4 changed files with 44 additions and 25 deletions

View File

@@ -120,6 +120,19 @@ void SSL3_BUFFER_set_data(SSL3_BUFFER *b, const unsigned char *d, int n)
b->offset = 0;
}
/*
* Clear the contents of an SSL3_BUFFER but retain any memory allocated
*/
void SSL3_BUFFER_clear(SSL3_BUFFER *b)
{
unsigned char *buf = b->buf;
size_t len = b->len;
memset(b, 0, sizeof(*b));
b->buf = buf;
b->len = len;
}
void SSL3_BUFFER_release(SSL3_BUFFER *b)
{
OPENSSL_free(b->buf);