From af4994f1f80e8cc15298f8178bc78ad57f3a1093 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Wed, 27 May 2026 15:29:46 +0200 Subject: [PATCH] fix(tests): fix memory leak in test_tpool_vs_actors Replace malloc with static memory to reduce possible memory leaks in test_tpool_vs_actors. Signed-off-by: Bartosz Podrygajlo --- common/utils/tests/test_tpool_vs_actors.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/utils/tests/test_tpool_vs_actors.c b/common/utils/tests/test_tpool_vs_actors.c index a907e07c9b..99d71aa9ca 100644 --- a/common/utils/tests/test_tpool_vs_actors.c +++ b/common/utils/tests/test_tpool_vs_actors.c @@ -6,6 +6,7 @@ #include "thread-pool.h" #include "task.h" #include "log.h" +#include #include #define NUM_THREADS 10 @@ -16,6 +17,8 @@ typedef struct { int actor_index; } actor_task_t; +struct timespec ts_arr[NUM_JOBS]; + long long delay_table[NUM_THREADS] = {0}; void calculate_delay(struct timespec* send_ts, int thread_index) @@ -32,7 +35,6 @@ void tpool_function(void* args) { int worker_id = get_tpool_worker_index(); calculate_delay((struct timespec*)args, worker_id); - free(args); } void actor_function(void* args) @@ -62,7 +64,7 @@ int main() // Push tasks to the thread pool for (int i = 0; i < NUM_JOBS; i++) { - struct timespec* ts = malloc(sizeof(struct timespec)); + struct timespec* ts = &ts_arr[i]; clock_gettime(CLOCK_MONOTONIC, ts); task.args = ts; pushTpool(&pool, task); @@ -78,7 +80,6 @@ int main() float average_delay = sum_delay / (NUM_JOBS * 1.0f); printf("Average task delay on tpool: %.2f ns\n", average_delay); - memset(delay_table, 0, sizeof(delay_table)); Actor_t actors[NUM_THREADS]; @@ -106,4 +107,4 @@ int main() average_delay = sum_delay / (NUM_JOBS * 1.0f); printf("Average task delay on actors: %.2f ns\n", average_delay); return 0; -} \ No newline at end of file +}