[PATCH] perf help:Fail check on dynamic allocation

zhaimingbing posted 1 patch 2 years ago
tools/perf/builtin-help.c | 9 +++++++++
1 file changed, 9 insertions(+)
[PATCH] perf help:Fail check on dynamic allocation
Posted by zhaimingbing 2 years ago
Return error  if dynamic allocation failed.

Signed-off-by: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
---
 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