From a9c694d5b6ea026a0c745e5b650993bf0f1c13dc Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 30 Jun 2014 18:46:08 +0200 Subject: [PATCH] use calloc instead of malloc+memset Signed-off-by: Felix Fietkau --- forwards.c | 5 +---- includes.c | 5 +---- ipsets.c | 5 +---- main.c | 4 +--- redirects.c | 5 +---- ubus.c | 11 +++-------- utils.c | 2 +- zones.c | 9 ++------- 8 files changed, 11 insertions(+), 35 deletions(-) diff --git a/forwards.c b/forwards.c index c7e7ba1..e27e4ee 100644 --- a/forwards.c +++ b/forwards.c @@ -48,13 +48,10 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p) if (strcmp(s->type, "forwarding")) continue; - forward = malloc(sizeof(*forward)); - + forward = calloc(1, sizeof(*forward)); if (!forward) continue; - memset(forward, 0, sizeof(*forward)); - forward->enabled = true; fw3_parse_options(forward, fw3_forward_opts, s); diff --git a/includes.c b/includes.c index 5022fbd..e2450a8 100644 --- a/includes.c +++ b/includes.c @@ -47,13 +47,10 @@ fw3_load_includes(struct fw3_state *state, struct uci_package *p) if (strcmp(s->type, "include")) continue; - include = malloc(sizeof(*include)); - + include = calloc(1, sizeof(*include)); if (!include) continue; - memset(include, 0, sizeof(*include)); - include->name = e->name; include->enabled = true; diff --git a/ipsets.c b/ipsets.c index 8f88885..5b319a5 100644 --- a/ipsets.c +++ b/ipsets.c @@ -203,13 +203,10 @@ fw3_alloc_ipset(void) { struct fw3_ipset *ipset; - ipset = malloc(sizeof(*ipset)); - + ipset = calloc(1, sizeof(*ipset)); if (!ipset) return NULL; - memset(ipset, 0, sizeof(*ipset)); - INIT_LIST_HEAD(&ipset->datatypes); ipset->enabled = true; diff --git a/main.c b/main.c index 17d71d1..455c049 100644 --- a/main.c +++ b/main.c @@ -45,12 +45,10 @@ build_state(bool runtime) struct uci_package *p = NULL; FILE *sf; - state = malloc(sizeof(*state)); - + state = calloc(1, sizeof(*state)); if (!state) error("Out of memory"); - memset(state, 0, sizeof(*state)); state->uci = uci_alloc_context(); if (!state->uci) diff --git a/redirects.c b/redirects.c index a21998b..f1fa1f4 100644 --- a/redirects.c +++ b/redirects.c @@ -232,13 +232,10 @@ fw3_load_redirects(struct fw3_state *state, struct uci_package *p) if (strcmp(s->type, "redirect")) continue; - redir = malloc(sizeof(*redir)); - + redir = calloc(1, sizeof(*redir)); if (!redir) continue; - memset(redir, 0, sizeof(*redir)); - INIT_LIST_HEAD(&redir->proto); INIT_LIST_HEAD(&redir->mac_src); diff --git a/ubus.c b/ubus.c index f5fd8c4..34e21b8 100644 --- a/ubus.c +++ b/ubus.c @@ -68,13 +68,10 @@ parse_subnet(enum fw3_family family, struct blob_attr *dict, int rem) struct blob_attr *cur; struct fw3_address *addr; - addr = malloc(sizeof(*addr)); - + addr = calloc(1, sizeof(*addr)); if (!addr) return NULL; - memset(addr, 0, sizeof(*addr)); - addr->set = true; addr->family = family; @@ -121,16 +118,14 @@ invoke_common(const char *net, bool device) return NULL; if (device) - dev = malloc(sizeof(*dev)); + dev = calloc(1, sizeof(*dev)); else addr = malloc(sizeof(*addr)); if ((device && !dev) || (!device && !addr)) goto fail; - if (device) - memset(dev, 0, sizeof(*dev)); - else + if (!device) INIT_LIST_HEAD(addr); blobmsg_for_each_attr(c, interfaces, r) { diff --git a/utils.c b/utils.c index 8ed52be..4f30955 100644 --- a/utils.c +++ b/utils.c @@ -225,7 +225,7 @@ __fw3_command_pipe(bool silent, const char *command, ...) return false; argn = 2; - args = malloc(argn * sizeof(arg)); + args = calloc(argn, sizeof(arg)); if (!args) return false; diff --git a/zones.c b/zones.c index fe507b0..53c6246 100644 --- a/zones.c +++ b/zones.c @@ -128,13 +128,10 @@ fw3_alloc_zone(void) { struct fw3_zone *zone; - zone = malloc(sizeof(*zone)); - + zone = calloc(1, sizeof(*zone)); if (!zone) return NULL; - memset(zone, 0, sizeof(*zone)); - INIT_LIST_HEAD(&zone->networks); INIT_LIST_HEAD(&zone->devices); INIT_LIST_HEAD(&zone->subnets); @@ -683,12 +680,10 @@ fw3_resolve_zone_addresses(struct fw3_zone *zone) struct fw3_address *addr, *tmp; struct list_head *addrs, *all; - all = malloc(sizeof(*all)); - + all = calloc(1, sizeof(*all)); if (!all) return NULL; - memset(all, 0, sizeof(*all)); INIT_LIST_HEAD(all); list_for_each_entry(net, &zone->networks, list) -- 2.25.1