1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

make use of new helper function: alloc()

This commit is contained in:
Steffen Vogel 2015-03-17 23:21:31 +01:00
parent 85d23eae40
commit 61b3e45bca
5 changed files with 9 additions and 34 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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!");

View file

@ -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;