chiark / gitweb /
bootchart: Convert malloc/memset to calloc
authorAuke Kok <auke-jan.h.kok@intel.com>
Thu, 10 Jan 2013 19:35:00 +0000 (11:35 -0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Jan 2013 20:21:48 +0000 (15:21 -0500)
src/bootchart/bootchart.c
src/bootchart/log.c

index 7bcfd982490f72bd14e9e1782d27860b8889e4ac..37d8fbe6e9add848a7eccb2cc8f3032f1a65ddd6 100644 (file)
@@ -232,12 +232,11 @@ int main(int argc, char *argv[])
         }
 
         /* start with empty ps LL */
-        ps_first = malloc(sizeof(struct ps_struct));
+        ps_first = calloc(1, sizeof(struct ps_struct));
         if (!ps_first) {
-                perror("malloc(ps_struct)");
+                perror("calloc(ps_struct)");
                 exit(EXIT_FAILURE);
         }
-        memset(ps_first, 0, sizeof(struct ps_struct));
 
         /* handle TERM/INT nicely */
         memset(&sig, 0, sizeof(struct sigaction));
index c697121814e7d6e848f01c5a6aaf0bf820f7c5dd..e41689d6111ce369b7e8d5347500122a93727a03 100644 (file)
@@ -225,21 +225,19 @@ schedstat_next:
                         char t[32];
                         struct ps_struct *parent;
 
-                        ps->next_ps = malloc(sizeof(struct ps_struct));
+                        ps->next_ps = calloc(1, sizeof(struct ps_struct));
                         if (!ps->next_ps) {
-                                perror("malloc(ps_struct)");
+                                perror("calloc(ps_struct)");
                                 exit (EXIT_FAILURE);
                         }
-                        memset(ps->next_ps, 0, sizeof(struct ps_struct));
                         ps = ps->next_ps;
                         ps->pid = pid;
 
-                        ps->sample = malloc(sizeof(struct ps_sched_struct) * (len + 1));
+                        ps->sample = calloc(len + 1, sizeof(struct ps_sched_struct));
                         if (!ps->sample) {
-                                perror("malloc(ps_struct)");
+                                perror("calloc(ps_struct)");
                                 exit (EXIT_FAILURE);
                         }
-                        memset(ps->sample, 0, sizeof(struct ps_sched_struct) * (len + 1));
 
                         pscount++;