diff --git a/server/src/cfg.c b/server/src/cfg.c index 0ead1d2a3..2999f140d 100644 --- a/server/src/cfg.c +++ b/server/src/cfg.c @@ -97,11 +97,7 @@ int config_parse_path(config_setting_t *cfg, int enabled = 1; int reverse = 0; - struct path *p = (struct path *) malloc(sizeof(struct path)); - if (!p) - error("Failed to allocate memory for path"); - - memset(p, 0, sizeof(struct path)); + struct path *p = alloc(sizeof(struct path)); /* Required settings */ if (!config_setting_lookup_string(cfg, "in", &in)) @@ -139,11 +135,7 @@ int config_parse_path(config_setting_t *cfg, list_add(*paths, p); if (reverse) { - struct path *rev = (struct path *) malloc(sizeof(struct path)); - if (!rev) - error("Failed to allocate memory for path"); - - memcpy(rev, p, sizeof(struct path)); + struct path *rev = alloc(sizeof(struct path)); rev->in = p->out; /* Swap in/out */ rev->out = p->in; @@ -167,12 +159,7 @@ int config_parse_node(config_setting_t *cfg, struct node **nodes) const char *type; int ret; - /* Allocate memory */ - struct node *n = (struct node *) malloc(sizeof(struct node)); - if (!n) - error("Failed to allocate memory for node"); - - memset(n, 0, sizeof(struct node)); + struct node *n = alloc(sizeof(struct node)); /* Required settings */ n->cfg = cfg; @@ -212,11 +199,7 @@ int config_parse_socket(config_setting_t *cfg, struct node *n) const char *local, *remote; int ret; - struct socket *s = (struct socket *) malloc(sizeof(struct socket)); - if (!s) - serror("Failed to allocate memory for socket"); - - memset(s, 0, sizeof(struct socket)); + struct socket *s = (struct socket *) alloc(sizeof(struct socket)); if (!config_setting_lookup_string(cfg, "remote", &remote)) cerror(cfg, "Missing remote address for node '%s'", n->name); @@ -237,11 +220,7 @@ int config_parse_socket(config_setting_t *cfg, struct node *n) /** @todo Netem settings are not usable AF_UNIX */ config_setting_t *cfg_netem = config_setting_get_member(cfg, "netem"); if (cfg_netem) { - s->netem = (struct netem *) malloc(sizeof(struct netem)); - if (!s->netem) - error("Failed to allocate memory for netem"); - - memset(s->netem, 0, sizeof(struct netem)); + s->netem = (struct netem *) alloc(sizeof(struct netem)); config_parse_netem(cfg_netem, s->netem); } diff --git a/server/src/hist.c b/server/src/hist.c index 742e11be2..cb20c0940 100644 --- a/server/src/hist.c +++ b/server/src/hist.c @@ -23,7 +23,7 @@ void hist_init(struct hist *h, double low, double high, double resolution) h->high = high; h->resolution = resolution; h->length = (high - low) / resolution; - h->data = malloc(h->length * sizeof(unsigned)); + h->data = alloc(h->length * sizeof(unsigned)); hist_reset(h); } diff --git a/server/src/if.c b/server/src/if.c index a1e5d7bcc..a8c99207d 100644 --- a/server/src/if.c +++ b/server/src/if.c @@ -26,11 +26,7 @@ struct interface *interfaces; struct interface * if_create(int index) { - struct interface *i = malloc(sizeof(struct interface)); - if (!i) - error("Failed to allocate memory for interface"); - else - memset(i, 0, sizeof(struct interface)); + struct interface *i = alloc(sizeof(struct interface)); i->index = index; if_indextoname(index, i->name); diff --git a/server/src/path.c b/server/src/path.c index 1a4c5793f..8d0e28516 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -67,7 +67,7 @@ static void * path_send(void *arg) static void * path_run(void *arg) { struct path *p = (struct path *) arg; - struct msg *m = malloc(sizeof(struct msg)); + struct msg *m = alloc(sizeof(struct msg)); if (!m) error("Failed to allocate memory for message!"); diff --git a/server/src/test.c b/server/src/test.c index e06901b22..594732f36 100644 --- a/server/src/test.c +++ b/server/src/test.c @@ -147,7 +147,7 @@ check: void test_rtt() { struct msg m = MSG_INIT(sizeof(struct timespec) / sizeof(float)); struct timespec *ts1 = (struct timespec *) &m.data; - struct timespec *ts2 = malloc(sizeof(struct timespec)); + struct timespec *ts2 = alloc(sizeof(struct timespec)); double rtt; double rtt_max = LLONG_MIN;