From d334a75c8ab47ba42922fc4f79cf25e79e634736 Mon Sep 17 00:00:00 2001 From: Sakthivel Velumani Date: Fri, 28 Feb 2025 19:01:56 -0500 Subject: [PATCH] Fix memory leak and possible crash nr_dlsim allocates memory on every SNR iteration without freeing it. This can lead to memory exhaustion. Fix this by allocating only once and reuse memory. Also, free it before exit. --- openair1/SIMULATION/NR_PHY/dlsim.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 5f5e7a9b05..534d11b448 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -959,6 +959,13 @@ printf("%d\n", slot); fprintf(csv_file,"avg_round,eff_rate,eff_throughput,TBS\n"); } //--------------- + + Sched_INFO = malloc(sizeof(*Sched_INFO)); + if (Sched_INFO == NULL) { + LOG_E(PHY, "out of memory\n"); + exit(1); + } + for (SNR = snr0; SNR < snr1 && !stop; SNR += .2) { varArray_t *table_tx=initVarArray(1000,sizeof(double)); @@ -1012,11 +1019,6 @@ printf("%d\n", slot); UE_harq_process->DLround = round; UE_harq_process->first_rx = 1; - Sched_INFO = malloc(sizeof(*Sched_INFO)); - if (Sched_INFO == NULL) { - LOG_E(PHY, "out of memory\n"); - exit(1); - } memset(Sched_INFO, 0, sizeof(*Sched_INFO)); Sched_INFO->sched_response_id = -1; @@ -1335,6 +1337,8 @@ printf("%d\n", slot); n_errs = n_errors[0]; } // NSR + free(Sched_INFO); + free_channel_desc_scm(gNB2UE); for (i = 0; i < n_tx; i++) {