Linux Trace Kernel
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: lihongtao <lihongtao@kylinos.cn>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/bootconfig: Fix null pointer when free buf
Date: Wed, 20 May 2026 00:04:12 +0900	[thread overview]
Message-ID: <20260520000412.907a3d930ff09e1c80c1177a@kernel.org> (raw)
In-Reply-To: <20260519031458.141050-1-lihongtao@kylinos.cn>

On Tue, 19 May 2026 11:14:58 +0800
lihongtao <lihongtao@kylinos.cn> wrote:

> In show_xbc() and delete_xbc(), if load_xbc_from_initrd failed,
> the buf may be NULL.

NACK, because free() can handle NULL correctly. See free(3)

   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 functions.   Otherwise,  or  if
       ptr  has already been freed, undefined behavior occurs.  If ptr is NULL, no opera‐
       tion is performed.

Thanks,

> 
> Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
> Signed-off-by: lihongtao <lihongtao@kylinos.cn>
> ---
>  tools/bootconfig/main.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
> index ddabde20585f..417d07a46f92 100644
> --- a/tools/bootconfig/main.c
> +++ b/tools/bootconfig/main.c
> @@ -328,7 +328,8 @@ static int show_xbc(const char *path, bool list)
>  		xbc_show_compact_tree();
>  	ret = 0;
>  out:
> -	free(buf);
> +	if (buf)
> +		free(buf);
>  
>  	return ret;
>  }
> @@ -360,7 +361,8 @@ static int delete_xbc(const char *path)
>  	} /* Ignore if there is no boot config in initrd */
>  
>  	close(fd);
> -	free(buf);
> +	if (buf)
> +		free(buf);
>  
>  	return ret;
>  }
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2026-05-19 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  3:14 [PATCH] tools/bootconfig: Fix null pointer when free buf lihongtao
2026-05-19 15:04 ` Masami Hiramatsu [this message]

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=20260520000412.907a3d930ff09e1c80c1177a@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=lihongtao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    /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