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 <bartosz.podrygajlo@openairinterface.org>
This commit is contained in:
Bartosz Podrygajlo
2026-05-27 15:29:46 +02:00
parent efdab585e2
commit af4994f1f8

View File

@@ -6,6 +6,7 @@
#include "thread-pool.h"
#include "task.h"
#include "log.h"
#include <stdio.h>
#include <time.h>
#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];