diff options
author | Matt Caswell <matt@openssl.org> | 2016-01-13 11:44:04 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-03-07 21:39:27 +0000 |
commit | 0220fee47f912c9c89efe24c09e10f4d452a4d42 (patch) | |
tree | 09acd16b45de65d81c35b689afd3ee608be9d430 /ssl/record/ssl3_record.c | |
parent | 94777c9c86a2b2ea2726c49d6c8f61078558beba (diff) |
Lazily initialise the compression buffer
With read pipelining we use multiple SSL3_RECORD structures for reading.
There are SSL_MAX_PIPELINES (32) of them defined (typically not all of these
would be used). Each one has a 16k compression buffer allocated! This
results in a significant amount of memory being consumed which, most of the
time, is not needed. This change swaps the allocation of the compression
buffer to be lazy so that it is only done immediately before it is actually
used.
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'ssl/record/ssl3_record.c')
-rw-r--r-- | ssl/record/ssl3_record.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c index 33122626ec..c910e690a2 100644 --- a/ssl/record/ssl3_record.c +++ b/ssl/record/ssl3_record.c @@ -157,24 +157,6 @@ void SSL3_RECORD_release(SSL3_RECORD *r, unsigned int num_recs) } } -int SSL3_RECORD_setup(SSL3_RECORD *r, unsigned int num_recs) -{ - unsigned int i; - - for (i = 0; i < num_recs; i++) { - if (r[i].comp == NULL) - r[i].comp = (unsigned char *) - OPENSSL_malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH); - if (r[i].comp == NULL) { - if (i > 0) - SSL3_RECORD_release(r, i); - return 0; - } - } - - return 1; -} - void SSL3_RECORD_set_seq_num(SSL3_RECORD *r, const unsigned char *seq_num) { memcpy(r->seq_num, seq_num, SEQ_NUM_SIZE); @@ -626,16 +608,23 @@ int ssl3_do_uncompress(SSL *ssl, SSL3_RECORD *rr) #ifndef OPENSSL_NO_COMP int i; + if (rr->comp == NULL) { + rr->comp = (unsigned char *) + OPENSSL_malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH); + } + if (rr->comp == NULL) + return 0; + i = COMP_expand_block(ssl->expand, rr->comp, SSL3_RT_MAX_PLAIN_LENGTH, rr->data, (int)rr->length); if (i < 0) - return (0); + return 0; else rr->length = i; rr->data = rr->comp; #endif - return (1); + return 1; } int ssl3_do_compress(SSL *ssl, SSL3_RECORD *wr) |