mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
selftests/net: bind_bhash: fix memory leak in bind_socket
The getaddrinfo() call in bind_socket() dynamically allocates memory for the result linked list that must be freed with freeaddrinfo(). However, none of the code paths after a successful getaddrinfo() call free this memory, causing a leak in every invocation of bind_socket(). Signed-off-by: longlong yan <yanlonglong@kylinos.cn> Link: https://patch.msgid.link/20260601013927.1835-1-yanlonglong@kylinos.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
edceeba4af
commit
dfcc2ff129
|
|
@ -52,18 +52,19 @@ static int bind_socket(int opt, const char *addr)
|
|||
err = setsockopt(sock_fd, SOL_SOCKET, opt, &reuse, sizeof(reuse));
|
||||
if (err) {
|
||||
perror("setsockopt failed");
|
||||
goto cleanup;
|
||||
goto err_free_info;
|
||||
}
|
||||
}
|
||||
|
||||
err = bind(sock_fd, res->ai_addr, res->ai_addrlen);
|
||||
if (err) {
|
||||
perror("failed to bind to port");
|
||||
goto cleanup;
|
||||
goto err_free_info;
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
return sock_fd;
|
||||
|
||||
err_free_info:
|
||||
freeaddrinfo(res);
|
||||
cleanup:
|
||||
close(sock_fd);
|
||||
return err;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user