From: Timo Kokkonen Date: Tue, 27 Sep 2011 15:30:08 +0000 (+0300) Subject: Replace malloc + memset with calloc X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain;h=6274976541f127db372daa1f394b82bfc0249771 Replace malloc + memset with calloc The libc has a function for allocating cleared memory, so use that instead of manually clearing the memory with memset. Signed-off-by: Timo Kokkonen --- diff --git a/pagemap.h b/pagemap.h index 3482b4d..34bcd75 100644 --- a/pagemap.h +++ b/pagemap.h @@ -200,12 +200,11 @@ static inline void init_parse_opts(struct parse_opts *p) static inline struct pidlist *alloc_pidlist(void) { - struct pidlist *p = malloc(sizeof(*p)); + struct pidlist *p = calloc(sizeof(*p), 1); if (p == NULL) return p; - memset(p, 0, sizeof(*p)); INIT_LIST_HEAD(&p->list); return p; diff --git a/parse.c b/parse.c index 9241526..5f3196c 100644 --- a/parse.c +++ b/parse.c @@ -32,11 +32,10 @@ static struct maps_list *alloc_maplist(void) { struct maps_list *map; - map = malloc(sizeof *map); + map = calloc(sizeof *map, 1); if (map == NULL) goto err; - memset(map, 0, sizeof(*map)); INIT_LIST_HEAD(&map->list); err: return map; @@ -46,7 +45,7 @@ static struct maps *alloc_map(void) { struct maps *map; - map = malloc(sizeof *map); + map = calloc(sizeof(*map), 1); if (map == NULL) goto err; @@ -283,8 +282,7 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe, FILE *file; char path[512]; - process = malloc(sizeof(*process)); - memset(process, 0, sizeof(*process)); + process = calloc(sizeof(*process), 1); INIT_LIST_HEAD(&process->list); process->pid = pid;