public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Weifeng Su <suweifeng1@huawei.com>
Cc: linux-xfs@vger.kernel.org, hch@lst.de, sandeen@sandeen.net,
	linfeilong@huawei.com, liuzhiqiang26@huawei.com
Subject: Re: [PATCH v2] libxcmd: add return value check for dynamic memory function
Date: Thu, 8 Jun 2023 07:46:24 -0700	[thread overview]
Message-ID: <20230608144624.GU1325469@frogsfrogsfrogs> (raw)
In-Reply-To: <20230608025146.64940-1-suweifeng1@huawei.com>

On Thu, Jun 08, 2023 at 10:51:46AM +0800, Weifeng Su wrote:
> The result check was missed and It cause the coredump like:
> 0x00005589f3e358dd in add_command (ci=0x5589f3e3f020 <health_cmd>) at command.c:37
> 0x00005589f3e337d8 in init_commands () at init.c:37
> init (argc=<optimized out>, argv=0x7ffecfb0cd28) at init.c:102
> 0x00005589f3e33399 in main (argc=<optimized out>, argv=<optimized out>) at init.c:112
> 
> Add check for realloc function to ignore this coredump and exit with
> error output
> 
> Signed-off-by: Weifeng Su <suweifeng1@huawei.com>

Looks good to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
> Changes since version 1:
> - Modify according to review opinions, Add more string 
> 
>  libxcmd/command.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libxcmd/command.c b/libxcmd/command.c
> index a76d1515..e2603097 100644
> --- a/libxcmd/command.c
> +++ b/libxcmd/command.c
> @@ -34,6 +34,10 @@ add_command(
>  	const cmdinfo_t	*ci)
>  {
>  	cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
> +	if (!cmdtab) {
> +		perror(_("adding libxcmd command"));
> +		exit(1);
> +	}
>  	cmdtab[ncmds - 1] = *ci;
>  	qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
>  }
> -- 
> 2.18.0.windows.1
> 

  reply	other threads:[~2023-06-08 14:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  2:51 [PATCH v2] libxcmd: add return value check for dynamic memory function Weifeng Su
2023-06-08 14:46 ` Darrick J. Wong [this message]
2023-06-12 12:23   ` Weifeng Su
2023-06-12 15:25     ` Darrick J. Wong
2023-06-13  7:52       ` Carlos Maiolino
  -- strict thread matches above, loose matches on Subject: below --
2023-06-08  5:40 Christoph Hellwig

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=20230608144624.GU1325469@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=linfeilong@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=liuzhiqiang26@huawei.com \
    --cc=sandeen@sandeen.net \
    --cc=suweifeng1@huawei.com \
    /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