[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240829055621.3890-1-zhujun2@cmss.chinamobile.com>
Date: Wed, 28 Aug 2024 22:56:21 -0700
From: Zhu Jun <zhujun2@...s.chinamobile.com>
To: akpm@...ux-foundation.org
Cc: linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
zhujun2@...s.chinamobile.com
Subject: [PATCH] tools/mm: Use calloc and check the potential memory allocation failure
Replace malloc with calloc and add memory allocating check
of comm_str before used.
Signed-off-by: Zhu Jun <zhujun2@...s.chinamobile.com>
---
tools/mm/page_owner_sort.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c
index e1f264444342..4e2329831810 100644
--- a/tools/mm/page_owner_sort.c
+++ b/tools/mm/page_owner_sort.c
@@ -368,9 +368,12 @@ static __u64 get_ts_nsec(char *buf)
static char *get_comm(char *buf)
{
- char *comm_str = malloc(TASK_COMM_LEN);
+ char *comm_str = calloc(TASK_COMM_LEN, sizeof(char));
- memset(comm_str, 0, TASK_COMM_LEN);
+ if (!comm_str) {
+ fprintf(stderr, "Out of memory\n");
+ return NULL;
+ }
search_pattern(&comm_pattern, comm_str, buf);
errno = 0;
--
2.17.1
Powered by blists - more mailing lists