Commit a9128087 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Memory leak still present.

parent 0129678d
Pipeline #94 failed with stage
......@@ -51,7 +51,7 @@ PrrtSocket *PrrtSocket_create(const bool is_sender)
sock_ptr->receivers = List_create();
} else {
check(PrrtForwardPacketTable_create(sock_ptr->forwardPacketTable) == 0, "Creating table failed.");
sock_ptr->forwardPacketTable = PrrtForwardPacketTable_create();
check(pthread_mutex_init(&sock_ptr->inQueueFilledMutex, NULL) == 0, "Mutex init failed.");
check(pthread_cond_init(&sock_ptr->inQueueFilledCv, NULL) == 0, "Cond init failed.");
......
#include <stdint.h>
#include "../../util/common.h"
#include "../../util/dbg.h"
#include "../../defines.h"
#include "../packet.h"
#include "forwardPacketTable.h"
bool is_position_relevant(const PrrtForwardPacketTable *fpt_ptr, prrtSequenceNumber_t seqno) {
bool is_position_relevant(const PrrtForwardPacketTable *fpt_ptr, prrtSequenceNumber_t seqno)
{
prrtSequenceNumber_t stop = (prrtSequenceNumber_t) (SEQNO_SPACE / 2 + fpt_ptr->start);
if (fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) {
if(fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) {
return false;
} else if (!(seqno <= stop || fpt_ptr->start <= seqno)) {
} else if(!(seqno <= stop || fpt_ptr->start <= seqno)) {
return false;
} else {
return Bitmap_get(fpt_ptr->bitmap, seqno);
}
}
void move_start(PrrtForwardPacketTable *fpt_ptr) {
void move_start(PrrtForwardPacketTable *fpt_ptr)
{
prrtSequenceNumber_t seqno = fpt_ptr->start;
while(1) {
if (Bitmap_get(fpt_ptr->bitmap, seqno)) {
if(Bitmap_get(fpt_ptr->bitmap, seqno)) {
break;
}
Bitmap_set(fpt_ptr->bitmap, seqno, true);
......@@ -31,19 +35,28 @@ void move_start(PrrtForwardPacketTable *fpt_ptr) {
fpt_ptr->start = seqno;
}
int PrrtForwardPacketTable_create(PrrtForwardPacketTable *fpt_prt) {
PrrtForwardPacketTable *PrrtForwardPacketTable_create()
{
PrrtForwardPacketTable *fpt_prt = calloc(1, sizeof(PrrtForwardPacketTable));
check_mem(fpt_prt);
fpt_prt->start = 1;
fpt_prt->bitmap = Bitmap_create(true, SEQNO_SPACE);
return EXIT_SUCCESS;
return fpt_prt;
error:
PERROR("Out of memory.%s", "");
return NULL;
}
bool PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt) {
bool PrrtForwardPacketTable_destroy(PrrtForwardPacketTable *fpt_prt)
{
Bitmap_destroy(fpt_prt->bitmap);
free(fpt_prt);
return true;
}
bool PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, prrtSequenceNumber_t seqno) {
bool PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, prrtSequenceNumber_t seqno)
{
bool res = is_position_relevant(fpt_ptr, seqno);
if(res) {
......@@ -56,13 +69,15 @@ bool PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *
return res;
}
bool PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable *forwardPacketTable, prrtSequenceNumber_t start,
prrtSequenceNumber_t length) {
bool PrrtForwardPacketTable_test_is_block_relevant(PrrtForwardPacketTable *forwardPacketTable,
prrtSequenceNumber_t start,
prrtSequenceNumber_t length)
{
// TODO: implement efficiently
bool res = false;
int i;
for (i = 0; i < length; i++) {
for(i = 0; i < length; i++) {
res = res || is_position_relevant(forwardPacketTable, (prrtSequenceNumber_t) (start + i));
}
......
......@@ -11,7 +11,7 @@ typedef struct {
Bitmap* bitmap;
} PrrtForwardPacketTable;
int PrrtForwardPacketTable_create(PrrtForwardPacketTable* fpt_prt);
PrrtForwardPacketTable * PrrtForwardPacketTable_create(void);
bool PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt);
bool PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, prrtSequenceNumber_t seqno);
......
Supports Markdown
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