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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user