forked from external/yambar
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:
parent
6bba9200cf
commit
b6e61f9c7e
11 changed files with 12 additions and 58 deletions
|
@ -327,20 +327,11 @@ out:
|
|||
static struct module *
|
||||
battery_new(const char *battery, struct particle *label, int poll_interval_secs)
|
||||
{
|
||||
struct private *m = malloc(sizeof(*m));
|
||||
struct private *m = calloc(1, sizeof(*m));
|
||||
m->label = label;
|
||||
m->poll_interval = poll_interval_secs;
|
||||
m->battery = strdup(battery);
|
||||
|
||||
m->manufacturer = NULL;
|
||||
m->model = NULL;
|
||||
|
||||
m->energy_full_design = 0;
|
||||
m->energy_full = 0;
|
||||
m->state = STATE_DISCHARGING;
|
||||
m->capacity = 0;
|
||||
m->energy = 0;
|
||||
m->power = 0;
|
||||
|
||||
struct module *mod = module_common_new();
|
||||
mod->private = m;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue