]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: ssl: use realloc() instead of free()+malloc()
authorWilly Tarreau <w@1wt.eu>
Fri, 26 Feb 2021 20:05:08 +0000 (21:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 26 Feb 2021 20:27:33 +0000 (21:27 +0100)
There was a free(ptr) followed by ptr=malloc(ptr, len), which is the
equivalent of ptr = realloc(ptr, len) but slower and less clean. Let's
replace this.

src/ssl_sock.c

index b10281a00dd7572ae70dc8c23f2e86561abeb4a7..2abd6661e809596393c378409847fec5b881b60b 100644 (file)
@@ -3996,8 +3996,8 @@ static int ssl_sess_new_srv_cb(SSL *ssl, SSL_SESSION *sess)
                if (s->ssl_ctx.reused_sess[tid].ptr && s->ssl_ctx.reused_sess[tid].allocated_size >= len) {
                        ptr = s->ssl_ctx.reused_sess[tid].ptr;
                } else {
-                       free(s->ssl_ctx.reused_sess[tid].ptr);
-                       ptr = s->ssl_ctx.reused_sess[tid].ptr = malloc(len);
+                       ptr = realloc(s->ssl_ctx.reused_sess[tid].ptr, len);
+                       s->ssl_ctx.reused_sess[tid].ptr = ptr;
                        s->ssl_ctx.reused_sess[tid].allocated_size = len;
                }
                if (s->ssl_ctx.reused_sess[tid].ptr) {