yambar/module.c
Daniel Eklöf b6e61f9c7e 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.
2019-02-09 11:11:31 +01:00

28 lines
516 B
C

#include "module.h"
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
struct module *
module_common_new(void)
{
struct module *mod = calloc(1, sizeof(*mod));
mtx_init(&mod->lock, mtx_plain);
mod->destroy = &module_default_destroy;
return mod;
}
void
module_default_destroy(struct module *mod)
{
mtx_destroy(&mod->lock);
free(mod);
}
struct exposable *
module_begin_expose(struct module *mod)
{
struct exposable *e = mod->content(mod);
e->begin_expose(e);
return e;
}