BUG/MINOR: ssl: fix double-free on failed realloc in ssl_sock.c

Recent commit 90bfbea7c0 ("BUG/MINOR: ssl: fix memory leaks on realloc
failure in ssl_sock.c") accidentally turned a memory leak in case of
allocation failure into a double-free: the original pointer must no
longer be released. In addition, the allocated_size has to be reset
in case of failure. This needs to be backported to 3.3 like previous
commit.
This commit is contained in:
Willy Tarreau 2026-04-27 08:38:31 +02:00
parent 720b3d1f56
commit 0522264eb4

View File

@ -4252,10 +4252,8 @@ static int ssl_sess_new_srv_cb(SSL *ssl, SSL_SESSION *sess)
/* insufficient storage, reallocate */
len = (len + 7) & -8; /* round to the nearest 8 bytes */
ptr = my_realloc2(ptr, len);
if (!ptr)
free(s->ssl_ctx.reused_sess[tid].ptr);
s->ssl_ctx.reused_sess[tid].ptr = ptr;
s->ssl_ctx.reused_sess[tid].allocated_size = len;
s->ssl_ctx.reused_sess[tid].allocated_size = ptr ? len : 0;
}
if (ptr) {