Skip to content

Commit 2c6fe24

Browse files
committed
MINOR: ssl_sock: avoid iterating realloc(+1) on stored context
The SSL context storage in servers is per-thread, and the contents are allocated for a length that is determined from the session. It turns out that placing some traces there revealed that the realloc() that is called to grow the area can be called multiple times in a row even for just health checks, to grow the area by just one or two bytes. Given that malloc() allocates in multiples of 8 or 16 anyway, let's round the allocated size up to the nearest multiple of 8 to avoid this unneeded operation.
1 parent 2cc53ec commit 2c6fe24

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/ssl_sock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,6 +4279,7 @@ static int ssl_sess_new_srv_cb(SSL *ssl, SSL_SESSION *sess)
42794279
if (s->ssl_ctx.reused_sess[tid].ptr && s->ssl_ctx.reused_sess[tid].allocated_size >= len) {
42804280
ptr = s->ssl_ctx.reused_sess[tid].ptr;
42814281
} else {
4282+
len = (len + 7) & -8; /* round to the nearest 8 bytes */
42824283
ptr = realloc(s->ssl_ctx.reused_sess[tid].ptr, len);
42834284
if (!ptr)
42844285
free(s->ssl_ctx.reused_sess[tid].ptr);

0 commit comments

Comments
 (0)