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