]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Replace malloc + memset with calloc
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 27 Sep 2011 15:30:08 +0000 (18:30 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 27 Sep 2011 15:36:57 +0000 (18:36 +0300)
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 <kaapeli@itanic.dy.fi>
pagemap.h
parse.c

index 3482b4d3e9458acbe4f2473b7ed2db1715a29c55..34bcd75271ffe2597bff6580686ffbc6b2512df0 100644 (file)
--- 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 9241526969727ca9dffdffba1cd4c9fd03376e75..5f3196c50cbfe1b242b2b0d846184c2a25b91d97 100644 (file)
--- 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;