Skip to content

Commit

Permalink
socket: fix potential memory leak in connect()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jow- committed May 13, 2024
1 parent 0d823e7 commit 8cf816d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8cf816d

Please sign in to comment.