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));
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) {
perror("malloc");
goto clean_exit;
@ -110,7 +110,7 @@ void srslte_enb_ul_free(srslte_enb_ul_t *q)
if (q) {
if (q->users) {
for (int i=0;i<SRSLTE_SIRNTI;i++) {
for (int i=0;i<=SRSLTE_SIRNTI;i++) {
if (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)
{
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)) {
fprintf(stderr, "Error setting PUCCH rnti\n");

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

@ -451,7 +451,7 @@ clean_exit:
void srslte_pucch_free(srslte_pucch_t *q) {
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);
}
free(q->users);

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

@ -117,6 +117,7 @@ static void* async_thread(void *h) {
return NULL;
}
}
uhd_async_metadata_free(&md);
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);
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) {
uhd_sensor_value_free(&handler->rssi_value);
}
handler->async_thread_running = false;
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);
free(handler);
/** Something else to close the USRP?? */
return 0;
}

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

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

@ -80,6 +80,7 @@ public:
************************************************************/
sched();
~sched();
void init(rrc_interface_mac *rrc, srslte::log *log);
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_) {
nof_mutex = 0;
max_mutex = max_mutex_;
params.max_prach_offset_us = 20;
}

@ -42,6 +42,7 @@ public:
phch_worker();
void init(phch_common *phy, srslte::log *log_h);
void stop();
void reset();
cf_t *get_buffer_rx();
@ -84,6 +85,8 @@ private:
srslte::log *log_h;
phch_common *phy;
bool initiated;
bool running;
cf_t *signal_buffer_rx;
cf_t *signal_buffer_tx;
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)
{
srslte_dft_exit();
srslte::byte_buffer_pool::cleanup();
boost::mutex::scoped_lock lock(enb_instance_mutex);
if(NULL != instance) {
delete instance;
@ -61,14 +62,15 @@ enb::enb()
enb::~enb()
{
srslte::byte_buffer_pool::cleanup();
}
bool enb::init(all_args_t *args_)
{
args = args_;
#ifndef LOG_STDOUT
logger.init(args->log.filename);
#endif
rf_log.init("RF ", &logger);
// Create array of pointers to phy_logs
@ -87,7 +89,9 @@ bool enb::init(all_args_t *args_)
s1ap_log.init("S1AP", &logger);
// Init logs
#ifndef LOG_STDOUT
logger.log("\n\n");
#endif
rf_log.set_level(srslte::LOG_LEVEL_INFO);
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));

@ -84,11 +84,15 @@ bool mac::init(mac_args_t *args_, srslte_cell_t *cell_, phy_interface_mac *phy,
started = true;
}
return started;
}
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++) {
srslte_softbuffer_tx_free(&bcch_softbuffer_tx[i]);
}
@ -113,16 +117,6 @@ void mac::reset()
/* Setup scheduler */
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()

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

@ -118,6 +118,17 @@ void phch_worker::init(phch_common* phy_, srslte::log *log_h_)
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_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);
@ -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);
initiated = true;
running = true;
#ifdef DEBUG_WRITE_FILE
f = fopen("test.dat", "w");
#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()
{
initiated = false;
@ -236,6 +264,10 @@ void phch_worker::work_imp()
{
uint32_t sf_ack;
if (!running) {
return;
}
pthread_mutex_lock(&mutex);
mac_interface_phy::ul_sched_t *ul_grants = phy->ul_grants;

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

@ -59,6 +59,7 @@ int prach_worker::init(srslte_cell_t *cell_, srslte_prach_cfg_t *prach_cfg_, mac
start(priority);
initiated = true;
sf_cnt = 0;
pending_tti = 0;
processed_tti = 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()
{
srslte_prach_free(&prach);
if (signal_buffer_rx) {
free(signal_buffer_rx);
}
pthread_mutex_lock(&mutex);
processed_tti = 99999;
running = false;

@ -26,6 +26,7 @@
#include <srslte/interfaces/sched_interface.h>
#include <srslte/asn1/liblte_rrc.h>
#include <upper/rrc.h>
#include "srslte/asn1/liblte_mme.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(&paging_mutex, NULL);
act_monitor.start(RRC_THREAD_PRIO);
bzero(&sr_sched, sizeof(sr_sched_t));
start(RRC_THREAD_PRIO);
@ -71,7 +73,6 @@ rrc::activity_monitor::activity_monitor(rrc* parent_)
{
running = true;
parent = parent_;
start(RRC_THREAD_PRIO);
}
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);
sib_buffer[i].N_bytes = (bitbuffer.N_bits-1)/8+1;
}
free(msg);
return nof_messages;
}
@ -604,6 +606,8 @@ void rrc::run_thread()
if (p.pdu) {
rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]);
}
pthread_mutex_lock(&user_mutex);
if (users.count(p.rnti) == 1) {
switch(p.lcid)
{
case RB_ID_SRB0:
@ -614,13 +618,20 @@ void rrc::run_thread()
parse_ul_dcch(p.rnti, p.lcid, p.pdu);
break;
case LCID_REM_USER:
pthread_mutex_unlock(&user_mutex);
usleep(10000);
rem_user(p.rnti);
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()

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

@ -188,6 +188,12 @@ private:
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) {
tid = tb_idx;
if (srslte_softbuffer_rx_init(&softbuffer, 110)) {

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

@ -163,9 +163,20 @@ private:
is_initiated = false;
is_grant_configured = false;
tti_last_tx = 0;
payload_buffer = NULL;
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)
{
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()
{
srslte_softbuffer_rx_free(&pch_softbuffer);
started = false;
ttisync.increase();
upper_timers_thread.thread_cancel();

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

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

Loading…
Cancel
Save