mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
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:
@@ -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];
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user