From: Simon Horman <horms@kernel.org>
To: Zongmin Zhou <min_halo@163.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, shuah@kernel.org, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: Re: [PATCH] selftests: net: avoid memory leak
Date: Wed, 27 Aug 2025 17:12:30 +0100 [thread overview]
Message-ID: <20250827161230.GB10519@horms.kernel.org> (raw)
In-Reply-To: <20250826031540.28010-1-min_halo@163.com>
On Tue, Aug 26, 2025 at 11:15:40AM +0800, Zongmin Zhou wrote:
> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>
> The buffer be used without free,fix it to avoid memory leak.
I'm assuming this is a short-lived user-space program.
And any memory is freed when it exits.
So I'm unsure about the value of this change.
>
> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
> ---
> tools/testing/selftests/net/cmsg_sender.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
> index a825e628aee7..5358aa09ecb9 100644
> --- a/tools/testing/selftests/net/cmsg_sender.c
> +++ b/tools/testing/selftests/net/cmsg_sender.c
> @@ -491,6 +491,7 @@ int main(int argc, char *argv[])
> if (err) {
> fprintf(stderr, "Can't resolve address [%s]:%s\n",
> opt.host, opt.service);
> + free(buf);
> return ERN_SOCK_CREATE;
> }
>
> @@ -501,6 +502,7 @@ int main(int argc, char *argv[])
> if (fd < 0) {
> fprintf(stderr, "Can't open socket: %s\n", strerror(errno));
> freeaddrinfo(ai);
> + free(buf);
> return ERN_RESOLVE;
> }
>
> @@ -575,5 +577,6 @@ int main(int argc, char *argv[])
> err_out:
> close(fd);
> freeaddrinfo(ai);
I think it would be nicer to add another label here, say err_free_buff,
and then use it in the previous two hunks.
> + free(buf);
> return err;
> }
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-08-27 16:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 3:15 Zongmin Zhou
2025-08-27 16:12 ` Simon Horman [this message]
2025-08-28 2:02 ` [PATCH v2] " Zongmin Zhou
2025-08-28 19:06 ` Simon Horman
2025-08-30 2:15 ` Jakub Kicinski
2025-09-01 5:45 ` [PATCH v3] " Zongmin Zhou
2025-09-01 16:45 ` Simon Horman
2025-09-03 0:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250827161230.GB10519@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=min_halo@163.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=zhouzongmin@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®