Commit 1776d366 authored by Andreas Schmidt's avatar Andreas Schmidt

Fix memory leak by proper termination of receiveDataThread.

parent f731098f
Pipeline #2582 passed with stages
in 1 minute and 25 seconds
......@@ -278,7 +278,7 @@ void *receive_data_loop(void *ptr) {
struct sockaddr_in remote;
socklen_t addrlen = sizeof(remote);
unsigned char buffer[MAX_PAYLOAD_LENGTH];
PrrtSocket *sock_ptr = ptr;
PrrtSocket *s = ptr;
while (1) {
XlapTimestampPlaceholder tsph1;
......@@ -290,7 +290,11 @@ void *receive_data_loop(void *ptr) {
struct timespec packet_recv_timestamp;
uint64_t packet_recv_cyclestamp = 0;
receive_from_socket(sock_ptr, buffer, &n, &remote, &addrlen, &packet_recv_timestamp, &packet_recv_cyclestamp);
receive_from_socket(s, buffer, &n, &remote, &addrlen, &packet_recv_timestamp, &packet_recv_cyclestamp);
if (!atomic_load_explicit(&s->closing, memory_order_acquire)) {
break;
}
debug(DEBUG_HARDSTAMPING, "Packet TS:\t%ld.%09ld; Who? %s", (long) packet_recv_timestamp.tv_sec,
packet_recv_timestamp.tv_nsec, inet_ntoa(remote.sin_addr));
XlapTimeStampClock(&tsph1, ts_any_packet, 0, LinkReceive);
......@@ -320,28 +324,28 @@ void *receive_data_loop(void *ptr) {
kind = ts_feedback_packet;
}
if (packetType == PACKET_TYPE_DATA || packetType == PACKET_TYPE_REDUNDANCY) {
sock_ptr->lastReceivedTimestamp = prrt_recv_timestamp;
s->lastReceivedTimestamp = prrt_recv_timestamp;
XlapCycleStampValue(sock_ptr, kind, seqno, ChannelReceive, packet_recv_cyclestamp);
XlapTimeStampValue(sock_ptr, kind, seqno, ChannelReceive, packet_recv_timestamp);
XlapCycleStampValue(s, kind, seqno, ChannelReceive, packet_recv_cyclestamp);
XlapTimeStampValue(s, kind, seqno, ChannelReceive, packet_recv_timestamp);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph1);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph2);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph3);
XlapTimestampPlaceholderUse(s, kind, seqno, &tsph1);
XlapTimestampPlaceholderUse(s, kind, seqno, &tsph2);
XlapTimestampPlaceholderUse(s, kind, seqno, &tsph3);
XlapTimeStampCycle(sock_ptr, kind, seqno, HandlePacketStart);
XlapTimeStampCycle(s, kind, seqno, HandlePacketStart);
if (packetType == PACKET_TYPE_DATA) {
handle_data_packet(sock_ptr, packet);
handle_data_packet(s, packet);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
handle_redundancy_packet(sock_ptr, packet);
handle_redundancy_packet(s, packet);
} else {
goto error;
}
send_feedback(sock_ptr, remote, seqno, prrt_recv_timestamp, sentTimestamp, packetType);
XlapTimeStampCycle(sock_ptr, kind, seqno, HandlePacketEnd);
send_feedback(s, remote, seqno, prrt_recv_timestamp, sentTimestamp, packetType);
XlapTimeStampCycle(s, kind, seqno, HandlePacketEnd);
} else if (packetType == PACKET_TYPE_FEEDBACK) {
handle_feedback_packet(sock_ptr, packet, prrt_recv_timestamp);
handle_feedback_packet(s, packet, prrt_recv_timestamp);
PrrtPacket_destroy(packet);
} else {
PrrtPacket_print(packet);
......@@ -349,10 +353,12 @@ void *receive_data_loop(void *ptr) {
}
debug(DEBUG_DATARECEIVER, "Cleanup");
PrrtSocket_cleanup(sock_ptr);
PrrtSocket_cleanup(s);
debug(DEBUG_DATARECEIVER, "Cleaned");
}
return NULL;
error:
PNOTIMPLEMENTED("SHOULD IMPLEMENT ERROR HANDLER HERE");
return NULL;
}
......@@ -324,7 +324,7 @@ int PrrtSocket_interrupt(PrrtSocket *s) {
}
if (s->receiveDataThread != 0) {
check(pthread_cancel(s->receiveDataThread) == 0, "Cancel failed.");
pthread_cancel(s->receiveDataThread);
check(pthread_join(s->receiveDataThread, res) == 0, "Join failed.");
pthread_attr_destroy(s->receiveDataThreadAttr);
s->receiveDataThread = 0;
......
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