On Thu, 29 Aug 2024 02:21:44 -0700 Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote: > Replace malloc with calloc and add null pointer check > in case of allocation failure. > > ... > > --- a/tools/mm/page_owner_sort.c > +++ b/tools/mm/page_owner_sort.c > @@ -368,9 +368,10 @@ 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) > + return NULL; It seems rather pointless doing this when the caller aren't coded to handle the NULL return. And really, for these little userspace tools it's OK for us to just assume that malloc() alway succeeds, isn't it?