Commit 8b5538db authored by Andreas Schmidt's avatar Andreas Schmidt

Replace malloc with calloc.

parent 66e94abc
......@@ -76,10 +76,10 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) {
PrrtCoder_get_coder(&coder, n, k);
gf** src = malloc(sizeof(gf*) * k);
gf** src = calloc(1, sizeof(gf*) * k);
LIST_FOREACH(block_ptr->data_blocks, first, next, cur) {
src[j] = malloc(sizeof(gf) * length);
src[j] = calloc(1, sizeof(gf) * length);
memset(src[j], 0, sizeof(gf) * length);
PrrtPacket* pkt = cur->value;
pkt->index = (uint8_t) j;
......@@ -90,9 +90,9 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, uint16_t *seqno) {
PrrtPacket *first_packet = (PrrtPacket*) block_ptr->data_blocks->first->value;
uint16_t base_seqno = first_packet->seqno;
gf** fec = malloc(sizeof(gf*) * r);
gf** fec = calloc(1, sizeof(gf*) * r);
for(j = 0; j < r; j++) {
fec[j] = malloc(sizeof(gf) * length);
fec[j] = calloc(1, sizeof(gf) * length);
memset(fec[j], 0, sizeof(gf) * length);
PrrtCoder_encode(coder, src, fec[j], j+k, length); // gf **src, gf *fec, int index, int sz
PrrtPacket* red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void*) fec[j], length, *seqno,
......@@ -122,8 +122,8 @@ void PrrtBlock_decode(PrrtBlock *block_ptr) {
PrrtCoder_get_coder(&coder, n, k);
gf** fec = malloc(sizeof(gf*) * n);
int *idx_p = malloc(k * sizeof(int));
gf** fec = calloc(n, sizeof(gf*));
int *idx_p = calloc(k,sizeof(int));
gather_data_packets(block_ptr, fec, idx_p);
......
......@@ -223,7 +223,7 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
packet_ptr->seqno = ntohs(*seqno_prt);
buf_ptr += 2;
void *payload_buffer = malloc(payload_len);
void *payload_buffer = calloc(1, payload_len);
check_mem(payload_buffer);
packet_ptr->payload = payload_buffer;
......@@ -354,7 +354,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
packet_ptr->index = 0;
packet_ptr->seqno = seqno;
void *content_buf = malloc(sizeof(PrrtPacketDataPayload) + data_len);
void *content_buf = calloc(1, sizeof(PrrtPacketDataPayload) + data_len);
check_mem(content_buf);
PrrtPacketDataPayload *source_payload = content_buf;
......@@ -382,7 +382,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr
PrrtCodingParams codingParams) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketRedundancyPayload));
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket));
check_mem(packet_ptr);
packet_ptr->type_priority = PACKET_TYPE_REDUNDANCY << 4;
......@@ -390,7 +390,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr
packet_ptr->index = index;
packet_ptr->seqno = seqno;
void *content_buf = malloc(sizeof(PrrtPacketRedundancyPayload) + data_len);
void *content_buf = calloc(1, sizeof(PrrtPacketRedundancyPayload) + data_len);
check_mem(content_buf);
PrrtPacketRedundancyPayload *redundancy_payload = content_buf;
......@@ -414,14 +414,14 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
uint16_t ngap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback) {
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket));
check_mem(packet_ptr);
packet_ptr->type_priority = PACKET_TYPE_FEEDBACK << 4;
packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = index;
packet_ptr->seqno = seqno;
PrrtPacketFeedbackPayload *payload = malloc(sizeof(PrrtPacketFeedbackPayload));
PrrtPacketFeedbackPayload *payload = calloc(1, sizeof(PrrtPacketFeedbackPayload));
check_mem(payload);
payload->group_round_trip_time = round_trip_time;
......
......@@ -51,7 +51,7 @@ void *receive_data_loop(void *ptr) {
remote_port = ntohs(remote.sin_port);
remote_host = inet_ntoa(remote.sin_addr);
packet = malloc(sizeof(PrrtPacket));
packet = calloc(1, sizeof(PrrtPacket));
check_mem(packet);
PrrtPacket_decode(buffer, (uint16_t) n, packet);
......@@ -92,7 +92,7 @@ void *receive_data_loop(void *ptr) {
block = BPTree_get(sock_ptr->blockStore, redundancyPayload->base_seqno);
if(block == NULL) {
PrrtCodingParams *cpar = malloc(sizeof(PrrtCodingParams));
PrrtCodingParams *cpar = calloc(1, sizeof(PrrtCodingParams));
PrrtCodingParams_init(cpar);
cpar->k = redundancyPayload->k;
cpar->n = redundancyPayload->n;
......
......@@ -47,7 +47,7 @@ void *send_data_loop(void *ptr) {
PrrtSocket *sock_ptr = ptr;
PrrtBlock *block = NULL;
PrrtCodingParams *cpar = malloc(sizeof(PrrtCodingParams));
PrrtCodingParams *cpar = calloc(1, sizeof(PrrtCodingParams));
PrrtCodingParams_init(cpar);
PrrtBlock_alloc(&block, cpar);
......
......@@ -48,7 +48,7 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t i
address.sin_port = htons(port);
check(bind(sock_ptr->dataSocketFd, (struct sockaddr *) &address, sizeof(address)) == EXIT_SUCCESS, "Cannot bind data socket.");
sock_ptr->forwardPacketTable = malloc(sizeof(PrrtForwardPacketTable));
sock_ptr->forwardPacketTable = calloc(1, sizeof(PrrtForwardPacketTable));
PrrtForwardPacketTable_create(sock_ptr->forwardPacketTable);
pthread_mutex_init(&sock_ptr->inQueueFilledMutex, NULL);
......@@ -83,7 +83,7 @@ int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t po
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len) {
pthread_mutex_lock(&sock_ptr->outQueueFilledMutex);
PrrtPacket *packet = malloc(sizeof(PrrtPacket));
PrrtPacket *packet = calloc(1, sizeof(PrrtPacket));
check_mem(packet);
PrrtPacket_create_data_packet(packet, 5, data, (uint32_t) data_len, sock_ptr->sequenceNumberSource++);
......@@ -144,7 +144,7 @@ PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, co
char *remote_host = inet_ntoa(remote.sin_addr);
debug("Received feedback %s:%d", remote_host, remote_port);
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket));
check_mem(packet_ptr);
PrrtPacket_decode(bufin, (uint16_t) n, packet_ptr);
return packet_ptr;
......
This diff is collapsed.
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