diff options
| author | longlong yan <yanlonglong@kylinos.cn> | 2026-06-01 04:39:27 +0300 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-06-03 05:27:25 +0300 |
| commit | dfcc2ff12925d99e858eaf539eaa4aaaf81fe2a6 (patch) | |
| tree | 6ebc29b91c7183947f75e636fd96bc6c43383ea2 /tools/testing | |
| parent | edceeba4af3df39ec7e446e86ead50bbbbc85849 (diff) | |
| download | linux-dfcc2ff12925d99e858eaf539eaa4aaaf81fe2a6.tar.xz | |
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>
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/net/bind_bhash.c | 9 |
1 files 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; |
