Add xzalloc function to reduce size.

This commit is contained in:
Roy Marples 2008-01-30 14:34:55 +00:00
parent b49f779779
commit 61e36be694
2 changed files with 19 additions and 21 deletions

View File

@ -211,8 +211,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
} }
#ifdef _KVM_GETPROC2 #ifdef _KVM_GETPROC2
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(*kp), &processes);
&processes);
#else #else
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes); kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
#endif #endif

View File

@ -43,6 +43,13 @@ struct lhead
char **list; 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) static char *get_shell_value (char *string)
{ {
char *p = string; char *p = string;
@ -156,15 +163,14 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptree) if (! deptree)
{ {
deptree = xmalloc (sizeof (rc_depinfo_t)); deptree = xzalloc (sizeof (rc_depinfo_t));
depinfo = deptree; depinfo = deptree;
} }
else else
{ {
depinfo->next = xmalloc (sizeof (rc_depinfo_t)); depinfo->next = xzalloc (sizeof (rc_depinfo_t));
depinfo = depinfo->next; depinfo = depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = xstrdup (e); depinfo->service = xstrdup (e);
deptype = NULL; deptype = NULL;
goto next; goto next;
@ -181,16 +187,14 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptype) if (! deptype)
{ {
depinfo->depends = xmalloc (sizeof (rc_deptype_t)); depinfo->depends = xzalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
memset (deptype, 0, sizeof (rc_deptype_t));
} }
else else
if (strcmp (deptype->type, type) != 0) if (strcmp (deptype->type, type) != 0)
{ {
deptype->next = xmalloc (sizeof (rc_deptype_t)); deptype->next = xzalloc (sizeof (rc_deptype_t));
deptype = deptype->next; deptype = deptype->next;
memset (deptype, 0, sizeof (rc_deptype_t));
} }
if (! deptype->type) if (! deptype->type)
@ -750,8 +754,7 @@ bool rc_deptree_update (void)
if (! (fp = popen (GENDEP, "r"))) if (! (fp = popen (GENDEP, "r")))
return (false); return (false);
deptree = xmalloc (sizeof (rc_depinfo_t)); deptree = xzalloc (sizeof (*deptree));
memset (deptree, 0, sizeof (rc_depinfo_t));
/* Phase 2 */ /* Phase 2 */
while ((line = rc_getline (fp))) while ((line = rc_getline (fp)))
@ -775,10 +778,9 @@ bool rc_deptree_update (void)
depinfo = last_depinfo; depinfo = last_depinfo;
else else
{ {
last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = xzalloc (sizeof (rc_depinfo_t));
depinfo = last_depinfo->next; depinfo = last_depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = xstrdup (service); depinfo->service = xstrdup (service);
} }
@ -800,15 +802,14 @@ bool rc_deptree_update (void)
{ {
if (! last_deptype) if (! last_deptype)
{ {
depinfo->depends = xmalloc (sizeof (rc_deptype_t)); depinfo->depends = xzalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
} }
else else
{ {
last_deptype->next = xmalloc (sizeof (rc_deptype_t)); last_deptype->next = xzalloc (sizeof (rc_deptype_t));
deptype = last_deptype->next; deptype = last_deptype->next;
} }
memset (deptype, 0, sizeof (rc_deptype_t));
deptype->type = xstrdup (type); deptype->type = xstrdup (type);
} }
} }
@ -876,9 +877,8 @@ next:
} }
if (! di) if (! di)
{ {
last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = xzalloc (sizeof (rc_depinfo_t));
di = last_depinfo->next; di = last_depinfo->next;
memset (di, 0, sizeof (rc_depinfo_t));
di->service = xstrdup (service); di->service = xstrdup (service);
} }
} }
@ -919,15 +919,14 @@ next:
{ {
if (! last_deptype) if (! last_deptype)
{ {
di->depends = xmalloc (sizeof (rc_deptype_t)); di->depends = xzalloc (sizeof (rc_deptype_t));
dt = di->depends; dt = di->depends;
} }
else else
{ {
last_deptype->next = xmalloc (sizeof (rc_deptype_t)); last_deptype->next = xzalloc (sizeof (rc_deptype_t));
dt = last_deptype->next; dt = last_deptype->next;
} }
memset (dt, 0, sizeof (rc_deptype_t));
dt->type = xstrdup (deppairs[i].addto); dt->type = xstrdup (deppairs[i].addto);
} }