On Thu, May 28, 2026 at 1:22 AM Bob ynn <[email protected]> wrote:
>
> From: bob ynn <[email protected]>
>
> 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().
Note that it's freed at exit().
>
> Fixes: c35ecb95c448 ("selftests/net: Add test for timing a bind request to a
> port with a populated bhash entry")
> Signed-off-by: bob ynn <[email protected]>
The change itself looks good, but see the thread below.
https://lore.kernel.org/netdev/[email protected]/
---8<---
Your email address seems to indicate that your real name is not "lazy.."
Please repost with the From / Author and Signed-off-by lines containing
your real (some approximation of "legal") name. Unicode characters are
accepted.
---8<---
> ---
> tools/testing/selftests/net/bind_bhash.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/net/bind_bhash.c
> b/tools/testing/selftests/net/bind_bhash.c
> index da04b0b19b73..2bd100777448 100644
> --- a/tools/testing/selftests/net/bind_bhash.c
> +++ b/tools/testing/selftests/net/bind_bhash.c
> @@ -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;
> --
> 2.43.0
>