diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-25 01:40:00 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-25 01:42:20 -0700 |
commit | 7ab5a513926846a3e20ef12d2888c5d2aea501a6 (patch) | |
tree | 02890922b78e19696c1357294a31b3ccf14a466f /src | |
parent | 58aa58b6a7b641f851335ae2af28315ac2de2c50 (diff) |
*: s/malloc/calloc/
Eliminate some 0/NULL initializations.
Diffstat (limited to 'src')
-rw-r--r-- | src/desktop.c | 3 | ||||
-rw-r--r-- | src/libvmon/vmon.c | 12 | ||||
-rw-r--r-- | src/window.c | 3 |
3 files changed, 6 insertions, 12 deletions
diff --git a/src/desktop.c b/src/desktop.c index 44c23f0..80f75f7 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -122,14 +122,13 @@ vwm_desktop_t * vwm_desktop_create(vwm_t *vwm, char *name) { vwm_desktop_t *desktop; - desktop = malloc(sizeof(vwm_desktop_t)); + desktop = calloc(1, sizeof(vwm_desktop_t)); if (desktop == NULL) { VWM_PERROR("Failed to allocate desktop"); goto _fail; } desktop->name = name == NULL ? name : strdup(name); - desktop->focused_window = NULL; list_add_tail(&desktop->desktops, &vwm->desktops); list_add_tail(&desktop->desktops_mru, &vwm->desktops_mru); diff --git a/src/libvmon/vmon.c b/src/libvmon/vmon.c index 16290b3..73afd17 100644 --- a/src/libvmon/vmon.c +++ b/src/libvmon/vmon.c @@ -309,7 +309,7 @@ _retry: if (BITTEST((*store)->changed, VMON_PROC_STAT_CMDLINE)) { if (prev_argc != (*store)->argc) { try_free((void **)&(*store)->argv); /* XXX could realloc */ - (*store)->argv = malloc((*store)->argc * sizeof(char *)); + (*store)->argv = calloc(1, (*store)->argc * sizeof(char *)); } for (argn = 0, arg = (*store)->cmdline.array, i = 0; i < (*store)->cmdline.len; i++) { @@ -591,14 +591,12 @@ static vmon_fobject_t * fobject_lookup_hinted(vmon_t *vmon, const char *path, vm if (!fobject) { /* create a new fobject */ - fobject = malloc(sizeof(vmon_fobject_t)); + fobject = calloc(1, sizeof(vmon_fobject_t)); fobject->type = VMON_FOBJECT_TYPE_PIPE; fobject->inum = inum; INIT_LIST_HEAD(&fobject->ref_fds); INIT_LIST_HEAD(&fobject->bucket); - fobject->refcnt = 0; - fobject->foo = NULL; list_add_tail(&fobject->bucket, &vmon->fobjects); vmon->fobjects_nr++; @@ -1093,7 +1091,7 @@ static int maybe_install_proc_callback(vmon_t *vmon, list_head_t *callbacks, voi } if (&cb->callbacks == callbacks) { - cb = malloc(sizeof(vmon_proc_callback_t)); + cb = calloc(1, sizeof(vmon_proc_callback_t)); if (!cb) return 0; @@ -1153,7 +1151,7 @@ vmon_proc_t * vmon_proc_monitor(vmon_t *vmon, vmon_proc_t *parent, int pid, vmon } } - proc = (vmon_proc_t *)malloc(sizeof(vmon_proc_t)); + proc = (vmon_proc_t *)calloc(1, sizeof(vmon_proc_t)); if (proc == NULL) return NULL; /* TODO: report an error */ @@ -1162,9 +1160,7 @@ vmon_proc_t * vmon_proc_monitor(vmon_t *vmon, vmon_proc_t *parent, int pid, vmon proc->generation = vmon->generation; proc->refcnt = 1; proc->is_new = 1; /* newly created process */ - proc->is_stale = 0; /* implicitly not stale, since it is new */ proc->is_thread = is_thread; - memset(proc->stores, 0, sizeof(proc->stores)); proc->parent = parent; INIT_LIST_HEAD(&proc->sample_callbacks); INIT_LIST_HEAD(&proc->children); diff --git a/src/window.c b/src/window.c index b90b0ae..4d4463b 100644 --- a/src/window.c +++ b/src/window.c @@ -464,7 +464,7 @@ vwm_window_t * vwm_win_manage_xwin(vwm_t *vwm, vwm_xwindow_t *xwin) goto _fail; } - if (!(vwin = (vwm_window_t *)malloc(sizeof(vwm_window_t)))) { + if (!(vwin = (vwm_window_t *)calloc(1, sizeof(vwm_window_t)))) { VWM_PERROR("Failed to allocate vwin"); goto _fail; } @@ -486,7 +486,6 @@ vwm_window_t * vwm_win_manage_xwin(vwm_t *vwm, vwm_xwindow_t *xwin) vwin->desktop = vwm->focused_desktop; vwin->autoconfigured = VWM_WIN_AUTOCONF_NONE; - vwin->mapping = vwin->unmapping = vwin->configuring = 0; vwin->shelved = (vwm->focused_context == VWM_CONTEXT_SHELF); /* if we're in the shelf when the window is created, the window is shelved */ vwin->client = xwin->attrs; /* remember whatever the current attributes are */ |