fixed memory leaks

master
Ismael Gomez 7 years ago
parent aff30ef1a4
commit 22f194182c

@ -50,7 +50,7 @@ int srslte_enb_ul_init(srslte_enb_ul_t *q,
bzero(q, sizeof(srslte_enb_ul_t)); bzero(q, sizeof(srslte_enb_ul_t));
q->users = calloc(sizeof(srslte_enb_ul_user_t*), SRSLTE_SIRNTI); q->users = calloc(sizeof(srslte_enb_ul_user_t*), (1+SRSLTE_SIRNTI));
if (!q->users) { if (!q->users) {
perror("malloc"); perror("malloc");
goto clean_exit; goto clean_exit;
@ -110,7 +110,7 @@ void srslte_enb_ul_free(srslte_enb_ul_t *q)
if (q) { if (q) {
if (q->users) { if (q->users) {
for (int i=0;i<SRSLTE_SIRNTI;i++) { for (int i=0;i<=SRSLTE_SIRNTI;i++) {
if (q->users[i]) { if (q->users[i]) {
free(q->users[i]); free(q->users[i]);
} }
@ -198,7 +198,7 @@ int srslte_enb_ul_set_cell(srslte_enb_ul_t *q, srslte_cell_t cell,
int srslte_enb_ul_add_rnti(srslte_enb_ul_t *q, uint16_t rnti) int srslte_enb_ul_add_rnti(srslte_enb_ul_t *q, uint16_t rnti)
{ {
if (!q->users[rnti]) { if (!q->users[rnti]) {
q->users[rnti] = malloc(sizeof(srslte_enb_ul_user_t)); q->users[rnti] = calloc(1, sizeof(srslte_enb_ul_user_t));
if (srslte_pucch_set_crnti(&q->pucch, rnti)) { if (srslte_pucch_set_crnti(&q->pucch, rnti)) {
fprintf(stderr, "Error setting PUCCH rnti\n"); fprintf(stderr, "Error setting PUCCH rnti\n");

@ -320,7 +320,7 @@ void srslte_pdsch_free(srslte_pdsch_t *q) {
if (q->is_ue) { if (q->is_ue) {
srslte_pdsch_free_rnti(q, 0); srslte_pdsch_free_rnti(q, 0);
} else { } else {
for (uint16_t u=0;u<SRSLTE_SIRNTI;u++) { for (int u=0;u<=SRSLTE_SIRNTI;u++) {
if (q->users[u]) { if (q->users[u]) {
srslte_pdsch_free_rnti(q, u); srslte_pdsch_free_rnti(q, u);
} }

@ -451,7 +451,7 @@ clean_exit:
void srslte_pucch_free(srslte_pucch_t *q) { void srslte_pucch_free(srslte_pucch_t *q) {
if (q->users) { if (q->users) {
for (int rnti=0;rnti<SRSLTE_SIRNTI;rnti++) { for (int rnti=0;rnti<=SRSLTE_SIRNTI;rnti++) {
srslte_pucch_clear_rnti(q, rnti); srslte_pucch_clear_rnti(q, rnti);
} }
free(q->users); free(q->users);

@ -295,7 +295,7 @@ void srslte_pusch_free(srslte_pusch_t *q) {
if (q->is_ue) { if (q->is_ue) {
srslte_pusch_free_rnti(q, 0); srslte_pusch_free_rnti(q, 0);
} else { } else {
for (int rnti=0;rnti<SRSLTE_SIRNTI;rnti++) { for (int rnti=0;rnti<=SRSLTE_SIRNTI;rnti++) {
srslte_pusch_free_rnti(q, rnti); srslte_pusch_free_rnti(q, rnti);
} }
} }

@ -117,6 +117,7 @@ static void* async_thread(void *h) {
return NULL; return NULL;
} }
} }
uhd_async_metadata_free(&md);
return NULL; return NULL;
} }
@ -457,15 +458,18 @@ int rf_uhd_close(void *h)
uhd_rx_metadata_free(&handler->rx_md_first); uhd_rx_metadata_free(&handler->rx_md_first);
uhd_rx_metadata_free(&handler->rx_md); uhd_rx_metadata_free(&handler->rx_md);
uhd_meta_range_free(&handler->rx_gain_range); uhd_meta_range_free(&handler->rx_gain_range);
uhd_tx_streamer_free(&handler->tx_stream);
uhd_rx_streamer_free(&handler->rx_stream);
if (handler->has_rssi) { if (handler->has_rssi) {
uhd_sensor_value_free(&handler->rssi_value); uhd_sensor_value_free(&handler->rssi_value);
} }
handler->async_thread_running = false; handler->async_thread_running = false;
pthread_join(handler->async_thread, NULL); pthread_join(handler->async_thread, NULL);
uhd_tx_streamer_free(&handler->tx_stream);
uhd_rx_streamer_free(&handler->rx_stream);
uhd_usrp_free(&handler->usrp); uhd_usrp_free(&handler->usrp);
free(handler);
/** Something else to close the USRP?? */ /** Something else to close the USRP?? */
return 0; return 0;
} }

@ -36,7 +36,7 @@ int srslte_cexptab_init(srslte_cexptab_t *h, uint32_t size) {
uint32_t i; uint32_t i;
h->size = size; h->size = size;
h->tab = malloc(sizeof(cf_t) * size); h->tab = malloc(sizeof(cf_t) * (1+size));
if (h->tab) { if (h->tab) {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
h->tab[i] = cexpf(_Complex_I * 2 * M_PI * (float) i / size); h->tab[i] = cexpf(_Complex_I * 2 * M_PI * (float) i / size);

@ -138,18 +138,23 @@ typedef struct {
Main UE class Main UE class
*******************************************************************************/ *******************************************************************************/
#define LOG_STDOUT
class enb class enb
:public enb_metrics_interface :public enb_metrics_interface {
{
public: public:
static enb* get_instance(void); static enb *get_instance(void);
static void cleanup(void); static void cleanup(void);
bool init(all_args_t *args_); bool init(all_args_t *args_);
void stop(); void stop();
void start_plot(); void start_plot();
static void rf_msg(srslte_rf_error_t error); static void rf_msg(srslte_rf_error_t error);
void handle_rf_msg(srslte_rf_error_t error); void handle_rf_msg(srslte_rf_error_t error);
// eNodeB metrics interface // eNodeB metrics interface
@ -160,20 +165,26 @@ public:
private: private:
static enb *instance; static enb *instance;
enb(); enb();
virtual ~enb(); virtual ~enb();
srslte::radio radio; srslte::radio radio;
srsenb::phy phy; srsenb::phy phy;
srsenb::mac mac; srsenb::mac mac;
srslte::mac_pcap mac_pcap; srslte::mac_pcap mac_pcap;
srsenb::rlc rlc; srsenb::rlc rlc;
srsenb::pdcp pdcp; srsenb::pdcp pdcp;
srsenb::rrc rrc; srsenb::rrc rrc;
srsenb::gtpu gtpu; srsenb::gtpu gtpu;
srsenb::s1ap s1ap; srsenb::s1ap s1ap;
srslte::logger_file logger; #ifdef LOG_STDOUT
srslte::logger_stdout logger;
#else
srslte::logger_file logger;
#endif
srslte::log_filter rf_log; srslte::log_filter rf_log;
std::vector<void*> phy_log; std::vector<void*> phy_log;
srslte::log_filter mac_log; srslte::log_filter mac_log;

@ -80,6 +80,7 @@ public:
************************************************************/ ************************************************************/
sched(); sched();
~sched();
void init(rrc_interface_mac *rrc, srslte::log *log); void init(rrc_interface_mac *rrc, srslte::log *log);
void set_metric(metric_dl *dl_metric, metric_ul *ul_metric); void set_metric(metric_dl *dl_metric, metric_ul *ul_metric);

@ -54,6 +54,7 @@ public:
phch_common(uint32_t max_mutex_) : tx_mutex(max_mutex_) { phch_common(uint32_t max_mutex_) : tx_mutex(max_mutex_) {
nof_mutex = 0;
max_mutex = max_mutex_; max_mutex = max_mutex_;
params.max_prach_offset_us = 20; params.max_prach_offset_us = 20;
} }

@ -42,6 +42,7 @@ public:
phch_worker(); phch_worker();
void init(phch_common *phy, srslte::log *log_h); void init(phch_common *phy, srslte::log *log_h);
void stop();
void reset(); void reset();
cf_t *get_buffer_rx(); cf_t *get_buffer_rx();
@ -84,6 +85,8 @@ private:
srslte::log *log_h; srslte::log *log_h;
phch_common *phy; phch_common *phy;
bool initiated; bool initiated;
bool running;
cf_t *signal_buffer_rx; cf_t *signal_buffer_rx;
cf_t *signal_buffer_tx; cf_t *signal_buffer_tx;
uint32_t tti_rx, tti_tx, tti_sched_ul, sf_rx, sf_tx, sf_sched_ul, tx_mutex_cnt; uint32_t tti_rx, tti_tx, tti_sched_ul, sf_rx, sf_tx, sf_sched_ul, tx_mutex_cnt;

@ -45,6 +45,7 @@ enb* enb::get_instance(void)
void enb::cleanup(void) void enb::cleanup(void)
{ {
srslte_dft_exit(); srslte_dft_exit();
srslte::byte_buffer_pool::cleanup();
boost::mutex::scoped_lock lock(enb_instance_mutex); boost::mutex::scoped_lock lock(enb_instance_mutex);
if(NULL != instance) { if(NULL != instance) {
delete instance; delete instance;
@ -61,14 +62,15 @@ enb::enb()
enb::~enb() enb::~enb()
{ {
srslte::byte_buffer_pool::cleanup();
} }
bool enb::init(all_args_t *args_) bool enb::init(all_args_t *args_)
{ {
args = args_; args = args_;
logger.init(args->log.filename); #ifndef LOG_STDOUT
logger.init(args->log.filename);
#endif
rf_log.init("RF ", &logger); rf_log.init("RF ", &logger);
// Create array of pointers to phy_logs // Create array of pointers to phy_logs
@ -87,7 +89,9 @@ bool enb::init(all_args_t *args_)
s1ap_log.init("S1AP", &logger); s1ap_log.init("S1AP", &logger);
// Init logs // Init logs
logger.log("\n\n"); #ifndef LOG_STDOUT
logger.log("\n\n");
#endif
rf_log.set_level(srslte::LOG_LEVEL_INFO); rf_log.set_level(srslte::LOG_LEVEL_INFO);
for (int i=0;i<args->expert.phy.nof_phy_threads;i++) { for (int i=0;i<args->expert.phy.nof_phy_threads;i++) {
((srslte::log_filter*) phy_log[i])->set_level(level(args->log.phy_level)); ((srslte::log_filter*) phy_log[i])->set_level(level(args->log.phy_level));

@ -84,11 +84,15 @@ bool mac::init(mac_args_t *args_, srslte_cell_t *cell_, phy_interface_mac *phy,
started = true; started = true;
} }
return started; return started;
} }
void mac::stop() void mac::stop()
{ {
for (uint32_t i=0;i<ue_db.size();i++) {
delete ue_db[i];
}
for (int i=0;i<NOF_BCCH_DLSCH_MSG;i++) { for (int i=0;i<NOF_BCCH_DLSCH_MSG;i++) {
srslte_softbuffer_tx_free(&bcch_softbuffer_tx[i]); srslte_softbuffer_tx_free(&bcch_softbuffer_tx[i]);
} }
@ -113,16 +117,6 @@ void mac::reset()
/* Setup scheduler */ /* Setup scheduler */
scheduler.reset(); scheduler.reset();
/* Setup SI-RNTI in PHY */
phy_h->add_rnti(SRSLTE_SIRNTI);
/* Setup P-RNTI in PHY */
phy_h->add_rnti(SRSLTE_PRNTI);
/* Setup RA-RNTI in PHY */
for (int i=0;i<10;i++) {
phy_h->add_rnti(1+i);
}
} }
uint32_t mac::get_unique_id() uint32_t mac::get_unique_id()

@ -20,11 +20,18 @@ namespace srsenb {
*******************************************************/ *******************************************************/
sched::sched() sched::sched()
{ {
current_tti = 0;
log_h = NULL; log_h = NULL;
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
reset(); reset();
} }
sched::~sched()
{
srslte_regs_free(&regs);
pthread_mutex_destroy(&mutex);
}
void sched::init(rrc_interface_mac *rrc_, srslte::log* log) void sched::init(rrc_interface_mac *rrc_, srslte::log* log)
{ {
sched_cfg.pdsch_max_mcs = 28; sched_cfg.pdsch_max_mcs = 28;
@ -39,6 +46,7 @@ void sched::init(rrc_interface_mac *rrc_, srslte::log* log)
int sched::reset() int sched::reset()
{ {
bzero(pending_msg3, sizeof(pending_msg3_t)*10);
bzero(pending_rar, sizeof(sched_rar_t)*SCHED_MAX_PENDING_RAR); bzero(pending_rar, sizeof(sched_rar_t)*SCHED_MAX_PENDING_RAR);
bzero(pending_sibs, sizeof(sched_sib_t)*MAX_SIBS); bzero(pending_sibs, sizeof(sched_sib_t)*MAX_SIBS);
ue_db.clear(); ue_db.clear();

@ -60,7 +60,7 @@ bool phch_common::init(srslte_cell_t *cell_, srslte::radio* radio_h_, mac_interf
is_first_of_burst = true; is_first_of_burst = true;
is_first_tx = true; is_first_tx = true;
for (uint32_t i=0;i<nof_mutex;i++) { for (uint32_t i=0;i<max_mutex;i++) {
pthread_mutex_init(&tx_mutex[i], NULL); pthread_mutex_init(&tx_mutex[i], NULL);
} }
reset(); reset();

@ -118,6 +118,17 @@ void phch_worker::init(phch_common* phy_, srslte::log *log_h_)
return; return;
} }
/* Setup SI-RNTI in PHY */
add_rnti(SRSLTE_SIRNTI);
/* Setup P-RNTI in PHY */
add_rnti(SRSLTE_PRNTI);
/* Setup RA-RNTI in PHY */
for (int i=0;i<10;i++) {
add_rnti(1+i);
}
srslte_pucch_set_threshold(&enb_ul.pucch, 0.8); srslte_pucch_set_threshold(&enb_ul.pucch, 0.8);
srslte_sch_set_max_noi(&enb_ul.pusch.ul_sch, phy->params.pusch_max_its); srslte_sch_set_max_noi(&enb_ul.pusch.ul_sch, phy->params.pusch_max_its);
srslte_enb_dl_set_amp(&enb_dl, phy->params.tx_amplitude); srslte_enb_dl_set_amp(&enb_dl, phy->params.tx_amplitude);
@ -125,12 +136,29 @@ void phch_worker::init(phch_common* phy_, srslte::log *log_h_)
Info("Worker %d configured cell %d PRB\n", get_id(), phy->cell.nof_prb); Info("Worker %d configured cell %d PRB\n", get_id(), phy->cell.nof_prb);
initiated = true; initiated = true;
running = true;
#ifdef DEBUG_WRITE_FILE #ifdef DEBUG_WRITE_FILE
f = fopen("test.dat", "w"); f = fopen("test.dat", "w");
#endif #endif
} }
void phch_worker::stop()
{
running = false;
pthread_mutex_lock(&mutex);
srslte_enb_dl_free(&enb_dl);
srslte_enb_ul_free(&enb_ul);
if (signal_buffer_rx) {
free(signal_buffer_rx);
}
if (signal_buffer_tx) {
free(signal_buffer_tx);
}
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
}
void phch_worker::reset() void phch_worker::reset()
{ {
initiated = false; initiated = false;
@ -236,6 +264,10 @@ void phch_worker::work_imp()
{ {
uint32_t sf_ack; uint32_t sf_ack;
if (!running) {
return;
}
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
mac_interface_phy::ul_sched_t *ul_grants = phy->ul_grants; mac_interface_phy::ul_sched_t *ul_grants = phy->ul_grants;

@ -134,6 +134,9 @@ void phy::stop()
{ {
tx_rx.stop(); tx_rx.stop();
workers_common.stop(); workers_common.stop();
for (uint32_t i=0;i<nof_workers;i++) {
workers[i].stop();
}
workers_pool.stop(); workers_pool.stop();
prach.stop(); prach.stop();
} }

@ -59,6 +59,7 @@ int prach_worker::init(srslte_cell_t *cell_, srslte_prach_cfg_t *prach_cfg_, mac
start(priority); start(priority);
initiated = true; initiated = true;
sf_cnt = 0;
pending_tti = 0; pending_tti = 0;
processed_tti = 0; processed_tti = 0;
return 0; return 0;
@ -66,6 +67,11 @@ int prach_worker::init(srslte_cell_t *cell_, srslte_prach_cfg_t *prach_cfg_, mac
void prach_worker::stop() void prach_worker::stop()
{ {
srslte_prach_free(&prach);
if (signal_buffer_rx) {
free(signal_buffer_rx);
}
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
processed_tti = 99999; processed_tti = 99999;
running = false; running = false;

@ -26,6 +26,7 @@
#include <srslte/interfaces/sched_interface.h> #include <srslte/interfaces/sched_interface.h>
#include <srslte/asn1/liblte_rrc.h> #include <srslte/asn1/liblte_rrc.h>
#include <upper/rrc.h>
#include "srslte/asn1/liblte_mme.h" #include "srslte/asn1/liblte_mme.h"
#include "upper/rrc.h" #include "upper/rrc.h"
@ -62,6 +63,7 @@ void rrc::init(rrc_cfg_t *cfg_,
pthread_mutex_init(&user_mutex, NULL); pthread_mutex_init(&user_mutex, NULL);
pthread_mutex_init(&paging_mutex, NULL); pthread_mutex_init(&paging_mutex, NULL);
act_monitor.start(RRC_THREAD_PRIO);
bzero(&sr_sched, sizeof(sr_sched_t)); bzero(&sr_sched, sizeof(sr_sched_t));
start(RRC_THREAD_PRIO); start(RRC_THREAD_PRIO);
@ -71,7 +73,6 @@ rrc::activity_monitor::activity_monitor(rrc* parent_)
{ {
running = true; running = true;
parent = parent_; parent = parent_;
start(RRC_THREAD_PRIO);
} }
void rrc::activity_monitor::stop() void rrc::activity_monitor::stop()
@ -149,6 +150,7 @@ uint32_t rrc::generate_sibs()
srslte_bit_pack_vector(bitbuffer.msg, sib_buffer[i].msg, bitbuffer.N_bits); srslte_bit_pack_vector(bitbuffer.msg, sib_buffer[i].msg, bitbuffer.N_bits);
sib_buffer[i].N_bytes = (bitbuffer.N_bits-1)/8+1; sib_buffer[i].N_bytes = (bitbuffer.N_bits-1)/8+1;
} }
free(msg);
return nof_messages; return nof_messages;
} }
@ -604,23 +606,32 @@ void rrc::run_thread()
if (p.pdu) { if (p.pdu) {
rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]); rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]);
} }
switch(p.lcid) pthread_mutex_lock(&user_mutex);
{ if (users.count(p.rnti) == 1) {
case RB_ID_SRB0: switch(p.lcid)
parse_ul_ccch(p.rnti, p.pdu); {
break; case RB_ID_SRB0:
case RB_ID_SRB1: parse_ul_ccch(p.rnti, p.pdu);
case RB_ID_SRB2: break;
parse_ul_dcch(p.rnti, p.lcid, p.pdu); case RB_ID_SRB1:
break; case RB_ID_SRB2:
case LCID_REM_USER: parse_ul_dcch(p.rnti, p.lcid, p.pdu);
usleep(10000); break;
rem_user(p.rnti); case LCID_REM_USER:
break; pthread_mutex_unlock(&user_mutex);
default: usleep(10000);
rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid); rem_user(p.rnti);
break; pthread_mutex_lock(&user_mutex);
break;
default:
rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid);
break;
}
} else {
printf("Discarting rnti=0x%xn", p.rnti);
rrc_log->warning("Discarting PDU for removed rnti=0x%x\n", p.rnti);
} }
pthread_mutex_unlock(&user_mutex);
} }
} }
void rrc::activity_monitor::run_thread() void rrc::activity_monitor::run_thread()

@ -347,6 +347,7 @@ bool s1ap::setup_s1()
uint16_t tmp16; uint16_t tmp16;
srslte::byte_buffer_t msg; srslte::byte_buffer_t msg;
LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT));
pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE;

@ -188,6 +188,12 @@ private:
bzero(&cur_grant, sizeof(Tgrant)); bzero(&cur_grant, sizeof(Tgrant));
} }
~dl_tb_process() {
if (is_initiated) {
srslte_softbuffer_rx_free(&softbuffer);
}
}
bool init(uint32_t pid_, dl_harq_entity *parent, uint32_t tb_idx) { bool init(uint32_t pid_, dl_harq_entity *parent, uint32_t tb_idx) {
tid = tb_idx; tid = tb_idx;
if (srslte_softbuffer_rx_init(&softbuffer, 110)) { if (srslte_softbuffer_rx_init(&softbuffer, 110)) {

@ -71,6 +71,9 @@ class ra_proc : public srslte::timer_callback
rar_grant_tti = 0; rar_grant_tti = 0;
msg3_flushed = false; msg3_flushed = false;
}; };
~ra_proc();
void init(phy_interface_mac *phy_h, void init(phy_interface_mac *phy_h,
rrc_interface_mac *rrc_, rrc_interface_mac *rrc_,
srslte::log *log_h, srslte::log *log_h,

@ -163,9 +163,20 @@ private:
is_initiated = false; is_initiated = false;
is_grant_configured = false; is_grant_configured = false;
tti_last_tx = 0; tti_last_tx = 0;
payload_buffer = NULL;
bzero(&cur_grant, sizeof(Tgrant)); bzero(&cur_grant, sizeof(Tgrant));
} }
~ul_harq_process()
{
if (is_initiated) {
if (payload_buffer) {
free(payload_buffer);
}
srslte_softbuffer_tx_free(&softbuffer);
}
}
bool init(uint32_t pid_, ul_harq_entity *parent) bool init(uint32_t pid_, ul_harq_entity *parent)
{ {
if (srslte_softbuffer_tx_init(&softbuffer, 110)) { if (srslte_softbuffer_tx_init(&softbuffer, 110)) {

@ -86,6 +86,8 @@ bool mac::init(phy_interface_mac *phy, rlc_interface_mac *rlc, rrc_interface_mac
void mac::stop() void mac::stop()
{ {
srslte_softbuffer_rx_free(&pch_softbuffer);
started = false; started = false;
ttisync.increase(); ttisync.increase();
upper_timers_thread.thread_cancel(); upper_timers_thread.thread_cancel();

@ -73,6 +73,10 @@ void ra_proc::init(phy_interface_mac* phy_h_,
reset(); reset();
} }
ra_proc::~ra_proc() {
srslte_softbuffer_rx_free(&softbuffer_rar);
}
void ra_proc::reset() { void ra_proc::reset() {
state = IDLE; state = IDLE;
msg3_transmitted = false; msg3_transmitted = false;

@ -145,6 +145,7 @@ phch_recv::~phch_recv() {
} }
srslte_ue_sync_free(&ue_sync); srslte_ue_sync_free(&ue_sync);
srslte_ue_dl_free(&ue_dl_measure); srslte_ue_dl_free(&ue_dl_measure);
srslte_ue_mib_free(&ue_mib);
srslte_ue_mib_sync_free(&ue_mib_sync); srslte_ue_mib_sync_free(&ue_mib_sync);
srslte_ue_cellsearch_free(&cs); srslte_ue_cellsearch_free(&cs);
} }

Loading…
Cancel
Save