BUG/MINOR: ssl_sock: fix possible memory leak on OOM
That's the classical realloc() issue: if it returns NULL, the old area
is not freed but we erase the pointer. It was brought by commit e18d4e828
("BUG/MEDIUM: ssl: backend TLS resumption with sni and TLSv1.3"), and
should be backported where this commit was backported.
(cherry picked from commit ff9e6538590ef26fd03a75474a7e1d2405f53fdd)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 94d7f8af8dcff1b4707000477a3dc77c0fbf59a2)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1741f226ecb27ece2f036a79478115a4610e8ef6)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ee5d6a0ef2da7a2b47ffcf9a3ca965290d8ea5f4)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index e69812f..408ea25 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -4035,6 +4035,8 @@
ptr = s->ssl_ctx.reused_sess[tid].ptr;
} else {
ptr = realloc(s->ssl_ctx.reused_sess[tid].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;
}