diff options
-rw-r--r-- | src/librc/librc-daemon.c | 3 | ||||
-rw-r--r-- | src/librc/librc-depend.c | 37 |
2 files changed, 19 insertions, 21 deletions
diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c index d697a681..e345f5f7 100644 --- a/src/librc/librc-daemon.c +++ b/src/librc/librc-daemon.c @@ -211,8 +211,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, } #ifdef _KVM_GETPROC2 - kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), - &processes); + kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(*kp), &processes); #else kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes); #endif diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index ad8e73d1..ca25de0c 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -43,6 +43,13 @@ struct lhead char **list; }; +static void *xzalloc (size_t size) +{ + void *value = xmalloc (size); + memset (value, 0, size); + return (value); +} + static char *get_shell_value (char *string) { char *p = string; @@ -156,15 +163,14 @@ rc_depinfo_t *rc_deptree_load (void) if (! deptree) { - deptree = xmalloc (sizeof (rc_depinfo_t)); + deptree = xzalloc (sizeof (rc_depinfo_t)); depinfo = deptree; } else { - depinfo->next = xmalloc (sizeof (rc_depinfo_t)); + depinfo->next = xzalloc (sizeof (rc_depinfo_t)); depinfo = depinfo->next; } - memset (depinfo, 0, sizeof (rc_depinfo_t)); depinfo->service = xstrdup (e); deptype = NULL; goto next; @@ -181,16 +187,14 @@ rc_depinfo_t *rc_deptree_load (void) if (! deptype) { - depinfo->depends = xmalloc (sizeof (rc_deptype_t)); + depinfo->depends = xzalloc (sizeof (rc_deptype_t)); deptype = depinfo->depends; - memset (deptype, 0, sizeof (rc_deptype_t)); } else if (strcmp (deptype->type, type) != 0) { - deptype->next = xmalloc (sizeof (rc_deptype_t)); + deptype->next = xzalloc (sizeof (rc_deptype_t)); deptype = deptype->next; - memset (deptype, 0, sizeof (rc_deptype_t)); } if (! deptype->type) @@ -750,8 +754,7 @@ bool rc_deptree_update (void) if (! (fp = popen (GENDEP, "r"))) return (false); - deptree = xmalloc (sizeof (rc_depinfo_t)); - memset (deptree, 0, sizeof (rc_depinfo_t)); + deptree = xzalloc (sizeof (*deptree)); /* Phase 2 */ while ((line = rc_getline (fp))) @@ -775,10 +778,9 @@ bool rc_deptree_update (void) depinfo = last_depinfo; else { - last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); + last_depinfo->next = xzalloc (sizeof (rc_depinfo_t)); depinfo = last_depinfo->next; } - memset (depinfo, 0, sizeof (rc_depinfo_t)); depinfo->service = xstrdup (service); } @@ -800,15 +802,14 @@ bool rc_deptree_update (void) { if (! last_deptype) { - depinfo->depends = xmalloc (sizeof (rc_deptype_t)); + depinfo->depends = xzalloc (sizeof (rc_deptype_t)); deptype = depinfo->depends; } else { - last_deptype->next = xmalloc (sizeof (rc_deptype_t)); + last_deptype->next = xzalloc (sizeof (rc_deptype_t)); deptype = last_deptype->next; } - memset (deptype, 0, sizeof (rc_deptype_t)); deptype->type = xstrdup (type); } } @@ -876,9 +877,8 @@ next: } if (! di) { - last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); + last_depinfo->next = xzalloc (sizeof (rc_depinfo_t)); di = last_depinfo->next; - memset (di, 0, sizeof (rc_depinfo_t)); di->service = xstrdup (service); } } @@ -919,15 +919,14 @@ next: { if (! last_deptype) { - di->depends = xmalloc (sizeof (rc_deptype_t)); + di->depends = xzalloc (sizeof (rc_deptype_t)); dt = di->depends; } else { - last_deptype->next = xmalloc (sizeof (rc_deptype_t)); + last_deptype->next = xzalloc (sizeof (rc_deptype_t)); dt = last_deptype->next; } - memset (dt, 0, sizeof (rc_deptype_t)); dt->type = xstrdup (deppairs[i].addto); } |