* [PATCH] libxcmd: add return value check for dynamic memory function
@ 2023-06-07 9:30 Weifeng Su
2023-06-07 13:30 ` Christoph Hellwig
2023-06-07 14:22 ` Darrick J. Wong
0 siblings, 2 replies; 3+ messages in thread
From: Weifeng Su @ 2023-06-07 9:30 UTC (permalink / raw)
To: linux-xfs, djwong, hch, sandeen; +Cc: linfeilong, liuzhiqiang26, Weifeng Su
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>
---
libxcmd/command.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libxcmd/command.c b/libxcmd/command.c
index a76d1515..47d050c3 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("realloc");
+ exit(1);
+ }
cmdtab[ncmds - 1] = *ci;
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
}
--
2.18.0.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libxcmd: add return value check for dynamic memory function
2023-06-07 9:30 [PATCH] libxcmd: add return value check for dynamic memory function Weifeng Su
@ 2023-06-07 13:30 ` Christoph Hellwig
2023-06-07 14:22 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2023-06-07 13:30 UTC (permalink / raw)
To: Weifeng Su; +Cc: linux-xfs, djwong, hch, sandeen, linfeilong, liuzhiqiang26
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libxcmd: add return value check for dynamic memory function
2023-06-07 9:30 [PATCH] libxcmd: add return value check for dynamic memory function Weifeng Su
2023-06-07 13:30 ` Christoph Hellwig
@ 2023-06-07 14:22 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2023-06-07 14:22 UTC (permalink / raw)
To: Weifeng Su; +Cc: linux-xfs, hch, sandeen, linfeilong, liuzhiqiang26
On Wed, Jun 07, 2023 at 05:30:18PM +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>
> ---
> libxcmd/command.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/libxcmd/command.c b/libxcmd/command.c
> index a76d1515..47d050c3 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("realloc");
The string argument should be more descriptive of /where/ we failed.
"realloc: Out of memory"
Tells us what failed, but not where; and we could probably figure that
out from strace data.
if (!cmdtab)
perror("add_command");
"add_command: Out of memory"
is better at implying that the triager should look for a function named
add_command and start there. You could even go as far as:
if (!cmdtab)
perror(_("adding libxcmd command"));
"adding libxcmd command: Out of memory"
which gives us a nice long string to grep.
--D
> + exit(1);
> + }
> cmdtab[ncmds - 1] = *ci;
> qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
> }
> --
> 2.18.0.windows.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-07 14:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-07 9:30 [PATCH] libxcmd: add return value check for dynamic memory function Weifeng Su
2023-06-07 13:30 ` Christoph Hellwig
2023-06-07 14:22 ` Darrick J. Wong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.