Commit 240e2d91 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Add assertions for memory allocation.

parent 4c5f38ef
......@@ -3,6 +3,7 @@
#include <sys/time.h>
#include <string.h>
#include <netinet/in.h>
#include <assert.h>
#include "packet.h"
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
......@@ -190,6 +191,7 @@ int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
buf_ptr += 2;
void* payload_buffer = malloc(payload_len);
assert(payload_buffer != NULL);
packet_ptr->payload = payload_buffer;
packet_ptr->payload_len = payload_len;
......@@ -295,6 +297,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
packet_ptr->seqno = 4711; // TODO: replace with sensible value
void *content_buf = malloc(sizeof(PrrtPacketDataPayload) + data_len);
assert(content_buf != NULL);
PrrtPacketDataPayload * source_payload = content_buf;
......@@ -321,12 +324,14 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback) {
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
assert(packet_ptr != NULL);
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));
assert(payload != NULL);
payload->group_round_trip_time = round_trip_time;
payload->forward_trip_time = forward_trip_time;
......
......@@ -5,6 +5,7 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include "../defines.h"
#include "socket.h"
#include "feedback_receiver.h"
......@@ -87,6 +88,7 @@ int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
PrrtPacket * packet = malloc(sizeof(PrrtPacket));
assert(packet != NULL);
PrrtPacket_create_data_packet(packet, 5, data, data_len);
List_push(sock_ptr->out_queue, packet);
......@@ -109,6 +111,7 @@ PrrtPacket *PrrtSocket_recv(PrrtSocket *sock_ptr) {
char *remote_host = inet_ntoa(remote.sin_addr);
PrrtPacket *packet = malloc(sizeof(PrrtPacket));
assert(packet != NULL);
PrrtPacket_decode(buffer, (uint16_t) n, packet);
// REPLY
......@@ -166,6 +169,7 @@ PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, void *bufin, size_t l
printf("RECV FEEDBACK: %s:%d\n", remote_host, remote_port);
PrrtPacket * packet_ptr = malloc(sizeof(PrrtPacket));
assert(packet_ptr != NULL);
PrrtPacket_decode(bufin, (uint16_t) n, packet_ptr);
return packet_ptr;
}
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