Commit 90b61797 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use calloc instead of malloc in places where it makes sense.

parent f2f6e359
......@@ -74,11 +74,10 @@ add_interface(char *ifname, struct interface_conf *if_conf)
}
}
ifp = malloc(sizeof(struct interface));
ifp = calloc(1, sizeof(struct interface));
if(ifp == NULL)
return NULL;
memset(ifp, 0, sizeof(struct interface));
strncpy(ifp->name, ifname, IF_NAMESIZE);
ifp->conf = if_conf ? if_conf : default_interface_conf;
ifp->bucket_time = now.tv_sec;
......
......@@ -84,7 +84,7 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
debugf("Creating neighbour %s on %s.\n",
format_address(address), ifp->name);
neigh = malloc(sizeof(struct neighbour));
neigh = calloc(1, sizeof(struct neighbour));
if(neigh == NULL) {
perror("malloc(neighbour)");
return NULL;
......@@ -92,15 +92,10 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
neigh->hello_seqno = -1;
memcpy(neigh->address, address, 16);
neigh->reach = 0;
neigh->txcost = INFINITY;
neigh->ihu_time = now;
neigh->hello_time = zero;
neigh->hello_interval = 0;
neigh->ihu_interval = 0;
neigh->hello_send_us = 0;
neigh->hello_rtt_receive_time = zero;
neigh->rtt = 0;
neigh->rtt_time = zero;
neigh->ifp = ifp;
neigh->next = neighs;
......
......@@ -127,7 +127,7 @@ record_resend(int kind, const unsigned char *prefix, unsigned char plen,
if(resend->ifp != ifp)
resend->ifp = NULL;
} else {
resend = malloc(sizeof(struct resend));
resend = calloc(1, sizeof(struct resend));
if(resend == NULL)
return -1;
resend->kind = kind;
......@@ -140,8 +140,6 @@ record_resend(int kind, const unsigned char *prefix, unsigned char plen,
resend->seqno = seqno;
if(id)
memcpy(resend->id, id, 8);
else
memset(resend->id, 0, 8);
resend->ifp = ifp;
resend->time = now;
resend->next = to_resend;
......
......@@ -377,7 +377,7 @@ route_stream(int which)
if(!check_specific_first())
fprintf(stderr, "Invariant failed: specific routes first in RIB.\n");
stream = malloc(sizeof(struct route_stream));
stream = calloc(1, sizeof(struct route_stream));
if(stream == NULL)
return NULL;
......@@ -939,7 +939,7 @@ update_route(const unsigned char *id,
return NULL;
}
route = malloc(sizeof(struct babel_route));
route = calloc(1, sizeof(struct babel_route));
if(route == NULL) {
perror("malloc(route)");
return NULL;
......@@ -956,8 +956,6 @@ update_route(const unsigned char *id,
route->hold_time = hold_time;
route->smoothed_metric = MAX(route_metric(route), INFINITY / 2);
route->smoothed_metric_time = now.tv_sec;
route->installed = 0;
memset(&route->channels, 0, sizeof(route->channels));
if(channels_len > 0)
memcpy(&route->channels, channels,
MIN(channels_len, DIVERSITY_HOPS));
......
......@@ -132,7 +132,7 @@ find_source(const unsigned char *id,
if(!create)
return NULL;
src = malloc(sizeof(struct source));
src = calloc(1, sizeof(struct source));
if(src == NULL) {
perror("malloc(source)");
return NULL;
......@@ -146,7 +146,6 @@ find_source(const unsigned char *id,
src->seqno = seqno;
src->metric = INFINITY;
src->time = now.tv_sec;
src->route_count = 0;
if(source_slots >= max_source_slots)
resize_source_table(max_source_slots < 1 ? 8 : 2 * max_source_slots);
......
......@@ -138,11 +138,10 @@ struct
xroute_stream *
xroute_stream()
{
struct xroute_stream *stream = malloc(sizeof(struct xroute_stream));
struct xroute_stream *stream = calloc(1, sizeof(struct xroute_stream));
if(stream == NULL)
return NULL;
stream->index = 0;
return stream;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment