Commit 89431151 authored by Andreas Schmidt's avatar Andreas Schmidt

Fix memory leak introduced by thread-pinning.

parent 087c58d4
Pipeline #947 failed with stages
in 51 seconds
......@@ -114,24 +114,24 @@ bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char *ipAddress, const uint16_t
if(sock_ptr->isSender) {
pthread_attr_t feedbackattr;
pthread_attr_t datasendattr;
pthread_attr_init(&feedbackattr);
pthread_attr_init(&datasendattr);
pin_thread_to_core(&feedbackattr, 1);
pin_thread_to_core(&datasendattr, 2);
check(pthread_create(&sock_ptr->receiveFeedbackThread, &feedbackattr, receive_feedback_loop,
sock_ptr->receiveFeedbackThreadAttr = calloc(1, sizeof(pthread_attr_t));
pthread_attr_init(sock_ptr->receiveFeedbackThreadAttr);
sock_ptr->sendDataThreadAttr = calloc(1, sizeof(pthread_attr_t));
pthread_attr_init(sock_ptr->sendDataThreadAttr);
pin_thread_to_core(sock_ptr->receiveFeedbackThreadAttr, 1);
pin_thread_to_core(sock_ptr->sendDataThreadAttr, 2);
check(pthread_create(&sock_ptr->receiveFeedbackThread, sock_ptr->receiveFeedbackThreadAttr, receive_feedback_loop,
(void *) sock_ptr) ==
EXIT_SUCCESS, "Cannot create receive feedback thread.");
check(pthread_create(&sock_ptr->sendDataThread, &datasendattr, send_data_loop, (void *) sock_ptr) ==
check(pthread_create(&sock_ptr->sendDataThread, sock_ptr->sendDataThreadAttr, send_data_loop, (void *) sock_ptr) ==
EXIT_SUCCESS,
"Cannot create send thread.");
} else {
pthread_attr_t datarecvattr;
pthread_attr_init(&datarecvattr);
pin_thread_to_core(&datarecvattr, 3);
check(pthread_create(&sock_ptr->receiveDataThread, &datarecvattr, receive_data_loop, (void *) sock_ptr) ==
sock_ptr->receiveDataThreadAttr = calloc(1, sizeof(pthread_attr_t));
pthread_attr_init(sock_ptr->receiveDataThreadAttr);
pin_thread_to_core(sock_ptr->receiveDataThreadAttr, 3);
check(pthread_create(&sock_ptr->receiveDataThread, sock_ptr->receiveDataThreadAttr, receive_data_loop, (void *) sock_ptr) ==
EXIT_SUCCESS,
"Cannot create data receiving thread.");
}
......@@ -225,6 +225,7 @@ int PrrtSocket_interrupt(PrrtSocket *sock_ptr)
check(pthread_mutex_unlock(&sock_ptr->outQueueFilledMutex) == 0, "Unlock failed.");
check(pthread_join(sock_ptr->sendDataThread, res) == 0, "Join failed.");
pthread_attr_destroy(sock_ptr->sendDataThreadAttr);
sock_ptr->sendDataThread = 0;
}
......@@ -235,13 +236,14 @@ int PrrtSocket_interrupt(PrrtSocket *sock_ptr)
check(pthread_cancel(sock_ptr->receiveDataThread) == 0, "Cancel failed.");
check(pthread_join(sock_ptr->receiveDataThread, res) == 0, "Join failed.");
pthread_attr_destroy(sock_ptr->receiveDataThreadAttr);
sock_ptr->receiveDataThread = 0;
}
if(sock_ptr->receiveFeedbackThread != 0) {
check(pthread_join(sock_ptr->receiveFeedbackThread, res) == 0, "Join failed.");
pthread_attr_destroy(sock_ptr->receiveFeedbackThreadAttr);
sock_ptr->receiveFeedbackThread = 0;
}
......@@ -324,6 +326,19 @@ int PrrtSocket_close(PrrtSocket *sock_ptr)
check(PrrtCodingParams_destroy(sock_ptr->codingParameters), "Could not destroy coding parameters.")
}
if(sock_ptr->sendDataThreadAttr != NULL) {
free(sock_ptr->sendDataThreadAttr);
}
if(sock_ptr->receiveDataThreadAttr != NULL) {
free(sock_ptr->receiveDataThreadAttr);
}
if(sock_ptr->receiveFeedbackThreadAttr != NULL) {
free(sock_ptr->receiveFeedbackThreadAttr);
}
close(sock_ptr->dataSocketFd);
close(sock_ptr->feedbackSocketFd);
debug(DEBUG_SOCKET, "Socket closed.");
......
......@@ -66,6 +66,10 @@ typedef struct prrtSocket {
PrrtCodingParams *codingParameters;
_Atomic(PrrtTimestampTable *) tstable[2];
pthread_attr_t* receiveFeedbackThreadAttr;
pthread_attr_t* sendDataThreadAttr;
pthread_attr_t* receiveDataThreadAttr;
} PrrtSocket;
......
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