From 8cf816d615fd063ba1463f64b6428e59a91e9651 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 13 May 2024 09:54:24 +0200 Subject: socket: fix potential memory leak in connect() If a non-string value which cannot be interpreted as socket address structure is passed to connect(), the function will leak the internal address vector when returning the error. Signed-off-by: Jo-Philipp Wich --- lib/socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/socket.c b/lib/socket.c index d0bd152..159f81c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -2228,8 +2228,11 @@ uc_socket_connect(uc_vm_t *vm, size_t nargs) uc_vector_grow(&addresses); ap = &addresses.entries[addresses.count++]; - if (!uv_to_sockaddr(host, &ap->ss, &ap->ai.ai_addrlen)) + if (!uv_to_sockaddr(host, &ap->ss, &ap->ai.ai_addrlen)) { + free(ai_hints); + uc_vector_clear(&addresses); return NULL; + } if (serv) { uint64_t port = ucv_to_unsigned(serv); -- cgit v1.2.3