From 172ceba5b60d02cfc3acfb0feb88f415e7837092 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Mon, 13 Mar 2023 23:43:12 +0000 Subject: Router: More accurately allocate request buffer memory. In nxt_router_prepare_msg() we create a buffer (nxt_unit_request_t *req) that gets sent to an application process that contains details about a client request. This buffer was always a little larger than needed due to allocating space for the remote address _and_ port and the local address _and_ port. We also allocate space for the local port separately. ->{local,remote}->length includes the port number and ':' and also the '[]' for IPv6. E.g [2001:db8::1]:8080 ->{local,remote}->address_length represents the length of the unadorned IP address. E.g 2001:db8::1 Update the buffer size so that we only allocate what is actually needed. Suggested-by: Zhidao HONG Cc: Zhidao HONG Reviewed-by: Zhidao HONG Signed-off-by: Andrew Clayton --- src/nxt_router.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nxt_router.c b/src/nxt_router.c index 4637cc68..17fe0418 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -5206,8 +5206,8 @@ nxt_router_prepare_msg(nxt_task_t *task, nxt_http_request_t *r, req_size = sizeof(nxt_unit_request_t) + r->method->length + 1 + r->version.length + 1 - + r->remote->length + 1 - + r->local->length + 1 + + r->remote->address_length + 1 + + r->local->address_length + 1 + nxt_sockaddr_port_length(r->local) + 1 + r->server_name.length + 1 + r->target.length + 1 -- cgit