X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils_mount.c;h=a36882c475ac2143395d628c7afdb31b3c249782;hb=88057ccbe844a073b1426216ef2e3dff8fe87da0;hp=ecf011d80d751e4f1c565fb2337136bf651cbd45;hpb=1ebf2f31bd2e080e6f42de640f0a3899a61501c0;p=collectd.git diff --git a/src/utils_mount.c b/src/utils_mount.c index ecf011d8..a36882c4 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -467,9 +467,8 @@ static cu_mount_t *cu_mount_getfsstat (void) return (NULL); } - if ((buf = malloc (bufsize * sizeof (*buf))) == NULL) + if ((buf = calloc (bufsize, sizeof (*buf))) == NULL) return (NULL); - memset (buf, '\0', bufsize * sizeof (STRUCT_STATFS)); /* The bufsize needs to be passed in bytes. Really. This is not in the * manpage.. -octo */ @@ -486,10 +485,9 @@ static cu_mount_t *cu_mount_getfsstat (void) for (i = 0; i < num; i++) { - if ((new = malloc (sizeof (*new))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mnttab' */ new->dir = sstrdup (buf[i].f_mntonname); new->spec_device = sstrdup (buf[i].f_mntfromname); @@ -540,10 +538,9 @@ static cu_mount_t *cu_mount_gen_getmntent (void) while (getmntent (fp, &mt) == 0) { - if ((new = malloc (sizeof (*new))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mnttab' */ new->dir = sstrdup (mt.mnt_mountp); new->spec_device = sstrdup (mt.mnt_special); @@ -598,9 +595,8 @@ static cu_mount_t *cu_mount_getmntent (void) while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) )) { - if ((new = malloc (sizeof (*new))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); /* Copy values from `struct mntent *' */ new->dir = sstrdup (me.mnt_dir); @@ -655,10 +651,9 @@ static cu_mount_t *cu_mount_getmntent (void) while ((me = getmntent (fp)) != NULL) { - if ((new = malloc (sizeof (*new))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mntent *' */ new->dir = sstrdup (me->mnt_dir); new->spec_device = sstrdup (me->mnt_fsname);