From: Petr Machata <petrm@nvidia•com>
To: heminhong <heminhong@kylinos•cn>
Cc: <stephen@networkplumber•org>, <netdev@vger•kernel.org>
Subject: Re: [PATCH v3] iproute2: prevent memory leak
Date: Wed, 15 Nov 2023 11:23:28 +0100 [thread overview]
Message-ID: <87y1ezwbk8.fsf@nvidia.com> (raw)
In-Reply-To: <20231115075650.33219-1-heminhong@kylinos.cn>
heminhong <heminhong@kylinos•cn> writes:
> When the return value of rtnl_talk() is greater than
> or equal to 0, 'answer' will be allocated.
> The 'answer' should be free after using,
> otherwise it will cause memory leak.
The patch also frees the memory when rtnl_talk() returns < 0. In that
case the answer has not been initialized. You should probably initialize
the answer to NULL.
> Signed-off-by: heminhong <heminhong@kylinos•cn>
> ---
> ip/link_gre.c | 1 +
> ip/link_gre6.c | 1 +
> ip/link_ip6tnl.c | 1 +
> ip/link_iptnl.c | 1 +
> ip/link_vti.c | 1 +
> ip/link_vti6.c | 1 +
> 6 files changed, 6 insertions(+)
>
> diff --git a/ip/link_gre.c b/ip/link_gre.c
> index 74a5b5e9..3d3fcbae 100644
> --- a/ip/link_gre.c
> +++ b/ip/link_gre.c
> @@ -113,6 +113,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
> get_failed:
> fprintf(stderr,
> "Failed to get existing tunnel info.\n");
> + free(answer);
> return -1;
> }
>
The context of this hunk is:
struct nlmsghdr *answer;
... answer untouched here ...
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
+ free(answer);
fprintf(stderr,
"Failed to get existing tunnel info.\n");
return -1;
}
If rtnl_talk() fails, answer is never initialized, so passing it to free
is invalid.
next prev parent reply other threads:[~2023-11-15 10:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 9:24 [PATCH] iproute2: prevent memory leak heminhong
2023-11-15 0:36 ` Stephen Hemminger
2023-11-15 2:37 ` [PATCH v2] " heminhong
2023-11-15 3:32 ` Florian Westphal
2023-11-15 3:33 ` Stephen Hemminger
2023-11-15 7:56 ` [PATCH v3] " heminhong
2023-11-15 10:23 ` Petr Machata [this message]
2023-11-16 3:13 ` [PATCH v4] " heminhong
2023-11-16 12:04 ` Andrea Claudi
2023-11-16 23:05 ` Stephen Hemminger
2023-11-17 0:45 ` Andrea Claudi
2023-11-17 3:31 ` Stephen Hemminger
2023-11-17 17:20 ` 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=87y1ezwbk8.fsf@nvidia.com \
--to=petrm@nvidia$(echo .)com \
--cc=heminhong@kylinos$(echo .)cn \
--cc=netdev@vger$(echo .)kernel.org \
--cc=stephen@networkplumber$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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