modules: use calloc() instead of malloc()

In cases where it makes sense, use calloc() instead of malloc():

* When allocating large objects with many members, many for which
  NULL/0 is a good default value.
* Arrays etc where we explicitly initialize to NULL anyway.
This commit is contained in:
Daniel Eklöf 2019-02-09 11:11:31 +01:00
parent 6bba9200cf
commit b6e61f9c7e
11 changed files with 12 additions and 58 deletions

View file

@ -565,20 +565,11 @@ refresh_in(struct module *mod, long milli_seconds)
static struct module *
mpd_new(const char *host, uint16_t port, struct particle *label)
{
struct private *priv = malloc(sizeof(*priv));
struct private *priv = calloc(1, sizeof(*priv));
priv->host = strdup(host);
priv->port = port;
priv->label = label;
priv->conn = NULL;
priv->state = STATE_OFFLINE;
priv->repeat = priv->random = priv->consume = false;
priv->album = NULL;
priv->artist = NULL;
priv->title = NULL;
priv->elapsed.value = 0;
priv->elapsed.when.tv_sec = priv->elapsed.when.tv_nsec = 0;
priv->duration = 0;
priv->refresh_thread_id = 0;
priv->refresh_abort_fd = -1;
struct module *mod = module_common_new();