:p
atchew
Login
Replace malloc with calloc and add null pointer check in case of allocation failure. Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com> --- tools/mm/page_owner_sort.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index XXXXXXX..XXXXXXX 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -XXX,XX +XXX,XX @@ 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; search_pattern(&comm_pattern, comm_str, buf); errno = 0; -- 2.17.1
Replace malloc with calloc and add null pointer check in case of allocation failure. Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com> --- tools/mm/page_owner_sort.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index XXXXXXX..XXXXXXX 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -XXX,XX +XXX,XX @@ 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; search_pattern(&comm_pattern, comm_str, buf); errno = 0; -- 2.17.1