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

@ -511,17 +511,14 @@ run(struct module *mod)
static struct module *
network_new(const char *iface, struct particle *label)
{
struct private *priv = malloc(sizeof(*priv));
struct private *priv = calloc(1, sizeof(*priv));
priv->iface = strdup(iface);
priv->label = label;
priv->nl_sock = -1;
priv->get_addresses = true;
priv->ifindex = -1;
memset(priv->mac, 0, sizeof(priv->mac));
priv->carrier = false;
priv->state = IF_OPER_DOWN;
memset(&priv->addrs, 0, sizeof(priv->addrs));
struct module *mod = module_common_new();
mod->private = priv;