From 044f938b768b8237bbe9448b900960a906409c7a Mon Sep 17 00:00:00 2001
From: "ruben.otto" <ruben.otto@informatik.hs-fulda.de>
Date: Fri, 14 Feb 2025 00:51:45 +0100
Subject: [PATCH] fix: fix daemon memory leak
---
daemon/src/main.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/daemon/src/main.c b/daemon/src/main.c
index fabb768..8bca43d 100644
--- a/daemon/src/main.c
+++ b/daemon/src/main.c
@@ -86,24 +86,19 @@ int main() {
sigaction(SIGINT, &signal_action, NULL);
while (1) {
- measurement_t *measurement = malloc(sizeof(measurement_t));
+ measurement_t measurement;
- if (measurement == NULL) {
- perror("Failed to allocate memory for measurement message");
- return EXIT_FAILURE;
- }
-
- if (recv_userspace_message(&userspace_receive_handle, measurement) != 0) {
+ if (recv_userspace_message(&userspace_receive_handle, &measurement) != 0) {
continue;
}
- printf("Received data from %d: ", measurement->id);
- print_measurement_data(measurement);
+ printf("Received data from %d: ", measurement.id);
+ print_measurement_data(&measurement);
data_t data = {
.sender_id = SENDER_ID,
.count = 1,
- .measurements = measurement,
+ .measurements = &measurement,
};
if (send_kernel_message(&kernel_send_handle, &data) == -1) {
--
GitLab