Subject: Re: [PATCH v2] iproute2: prevent memory leak

From: Stephen Hemminger <[email-masked]>
Date: Tue, 14 Nov 2023 19:33:50 -0800

On Wed, 15 Nov 2023 10:37:03 +0800
heminhong <[email-masked]> 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 <[email-masked]>

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.