public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber•org>
To: heminhong <heminhong@kylinos•cn>
Cc: netdev@vger•kernel.org
Subject: Re: [PATCH v2] iproute2: prevent memory leak
Date: Tue, 14 Nov 2023 19:33:50 -0800	[thread overview]
Message-ID: <20231114193350.475050ae@hermes.local> (raw)
In-Reply-To: <20231115023703.15417-1-heminhong@kylinos.cn>

On Wed, 15 Nov 2023 10:37:03 +0800
heminhong <heminhong@kylinos•cn> wrote:

> When the return value of rtnl_talk() is less than 0, 'answer' does not
> need to release. When the return value of rtnl_talk() is greater than
> or equal to 0, 'answer' will be allocated, if subsequent processing fails,
> the memory should be free, otherwise it will cause memory leak.
> 
> Signed-off-by: heminhong <heminhong@kylinos•cn>

No null check needed before free().

   free()
       The  free()  function  frees  the memory space pointed to by ptr, which
       must have been returned by a previous call to malloc() or related func‐
       tions.  Otherwise, or if ptr has already been freed, undefined behavior
       occurs.  If ptr is NULL, no operation is performed.

  parent reply	other threads:[~2023-11-15  3: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 [this message]
2023-11-15  7:56       ` [PATCH v3] " heminhong
2023-11-15 10:23         ` Petr Machata
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=20231114193350.475050ae@hermes.local \
    --to=stephen@networkplumber$(echo .)org \
    --cc=heminhong@kylinos$(echo .)cn \
    --cc=netdev@vger$(echo .)kernel.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