[PATCH] perf help:Fail check on dynamic allocation

From: zhaimingbing
Date: Fri Nov 24 2023 - 03:39:30 EST


Return NULL if dynamic allocation failed.

Signed-off-by: zhaimingbing <zhaimingbing@xxxxxxxxxxxxxxxxxxxx>
---
tools/perf/builtin-help.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index b2a368ae2..e89734dbb 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -196,6 +196,9 @@ static void add_man_viewer(const char *name)
while (*p)
p = &((*p)->next);
*p = zalloc(sizeof(**p) + len + 1);
+ if(!*p)
+ return NULL;
+
strcpy((*p)->name, name);
}

@@ -211,6 +214,8 @@ static void do_add_man_viewer_info(const char *name,
const char *value)
{
struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1);
+ if(!new)
+ return NULL;

strncpy(new->name, name, len);
new->info = strdup(value);
--
2.33.0