particles: 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:05:12 +01:00
parent 29e9cea1dd
commit 6bba9200cf
7 changed files with 16 additions and 23 deletions

View file

@ -111,7 +111,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
pp = p->default_particle;
}
struct eprivate *e = malloc(sizeof(*e));
struct eprivate *e = calloc(1, sizeof(*e));
e->exposable = pp->instantiate(pp, tags);
char *on_click = tags_expand_template(particle->on_click_template, tags);
@ -151,7 +151,7 @@ map_new(struct particle *common, const char *tag,
const struct particle_map particle_map[], size_t count,
struct particle *default_particle)
{
struct private *priv = malloc(sizeof(*priv));
struct private *priv = calloc(1, sizeof(*priv));
priv->tag = strdup(tag);
priv->default_particle = default_particle;
priv->count = count;