[PATCH] perf help:Fail check on dynamic allocation

From: zhaimingbing
Date: Wed Nov 29 2023 - 04:42:15 EST


Return error if dynamic allocation failed.

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

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index b2a368ae2..ca05cc795 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -196,6 +196,11 @@ static void add_man_viewer(const char *name)
while (*p)
p = &((*p)->next);
*p = zalloc(sizeof(**p) + len + 1);
+ if(!*p) {
+ pr_err("Failed to zalloc man viewer list\n");
+ return ;
+ }
+
strcpy((*p)->name, name);
}

@@ -211,6 +216,10 @@ 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) {
+ pr_err("Failed to zalloc man viewer info list\n");
+ return ;
+ }

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