From 5dcf3b3563b69e6b08311a28d58c494fa9dff510 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 8 Jul 2019 14:36:33 +0200 Subject: [PATCH] Fix phy memory leaks --- srsue/hdr/phy/phy.h | 6 +++--- srsue/src/phy/phy.cc | 14 +++++++------- srsue/src/phy/sync.cc | 13 +++++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 6cf6dcd1f..8ab78baed 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -142,9 +142,9 @@ private: const static int SF_RECV_THREAD_PRIO = 1; const static int WORKERS_THREAD_PRIO = 2; - radio_interface_phy* radio = nullptr; - std::vector log_vec; - srslte::logger* logger = nullptr; + radio_interface_phy* radio = nullptr; + std::vector > log_vec; + srslte::logger* logger = nullptr; srslte::log* log_h = nullptr; srslte::log* log_phy_lib_h = nullptr; diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 32d41fc57..cd361434c 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -137,7 +137,7 @@ int phy::init(const phy_args_t& args_, srslte::logger* logger_) mylog->init(tmp, logger, true); mylog->set_level(args.log.phy_level); mylog->set_hex_limit(args.log.phy_hex_limit); - log_vec.push_back(mylog); + log_vec.push_back(std::move(std::unique_ptr(mylog))); } // Add PHY lib log @@ -148,13 +148,13 @@ int phy::init(const phy_args_t& args_, srslte::logger* logger_) lib_log->init(tmp, logger, true); lib_log->set_level(args.log.phy_lib_level); lib_log->set_hex_limit(args.log.phy_hex_limit); - log_vec.push_back(lib_log); + log_vec.push_back(std::move(std::unique_ptr(lib_log))); } else { log_vec.push_back(nullptr); } // set default logger - log_h = log_vec.at(0); + log_h = log_vec.at(0).get(); if (!check_args(args)) { return false; @@ -162,7 +162,7 @@ int phy::init(const phy_args_t& args_, srslte::logger* logger_) nof_workers = args.nof_phy_threads; if (log_vec[nof_workers]) { - this->log_phy_lib_h = (srslte::log*)log_vec[0]; + this->log_phy_lib_h = (srslte::log*)log_vec[0].get(); srslte_phy_log_register_handler(this, srslte_phy_handler); } else { this->log_phy_lib_h = nullptr; @@ -177,12 +177,12 @@ int phy::init(const phy_args_t& args_, srslte::logger* logger_) void phy::run_thread() { prach_buffer.init(SRSLTE_MAX_PRB, log_h); - common.init(&args, (srslte::log*)log_vec[0], radio, stack); + common.init(&args, (srslte::log*)log_vec[0].get(), radio, stack); // Add workers to workers pool and start threads for (uint32_t i=0;i( - new sf_worker(SRSLTE_MAX_PRB, &common, (srslte::log*)log_vec[i], (srslte::log*)log_vec[nof_workers], &sfsync)); + auto w = std::unique_ptr(new sf_worker( + SRSLTE_MAX_PRB, &common, (srslte::log*)log_vec[i].get(), (srslte::log*)log_vec[nof_workers].get(), &sfsync)); workers_pool.init_worker(i, w.get(), WORKERS_THREAD_PRIO, args.worker_cpu_mask); workers.push_back(std::move(w)); } diff --git a/srsue/src/phy/sync.cc b/srsue/src/phy/sync.cc index 94019029c..11db44039 100644 --- a/srsue/src/phy/sync.cc +++ b/srsue/src/phy/sync.cc @@ -106,17 +106,14 @@ void sync::init(radio_interface_phy* _radio, sync::~sync() { - if (running) { - uint32_t nof_rf_channels = worker_com->args->nof_rf_channels * worker_com->args->nof_rx_ant; - for (uint32_t r = 0; r < worker_com->args->nof_radios; r++) { - for (uint32_t p = 0; p < nof_rf_channels; p++) { - if (sf_buffer[r][p]) { - free(sf_buffer[r][p]); - } + for (uint32_t r = 0; r < SRSLTE_MAX_RADIOS; r++) { + for (uint32_t p = 0; p < SRSLTE_MAX_PORTS; p++) { + if (sf_buffer[r][p]) { + free(sf_buffer[r][p]); } } - srslte_ue_sync_free(&ue_sync); } + srslte_ue_sync_free(&ue_sync); } void sync::stop()