aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-12-03 18:17:18 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2018-12-04 15:57:37 +0000
commit5cea18e5cbb1194b15df09f822345524380b94d2 (patch)
treef673aad51e7b3d062b4729319d89e59b8e1e2cb4
parent4adc4eb8d00c65156b6d35352797a9975270d23e (diff)
lms: Make sure LMS_Close is called when Device is torn down
This change fixes lots of memory leaks inside libLimeSuite as announced by ASan after exiting the osmo-trx process (throgh CTRL+C for instance). This way also we make sure libLimeSuite can communicate with the HW and close whatever subsystems were enabled during LMS_Open time. Change-Id: I56ffb87079e34aa2d0322fd2ca6429742f9f7640
-rw-r--r--Transceiver52M/device/lms/LMSDevice.cpp10
-rw-r--r--Transceiver52M/device/lms/LMSDevice.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp
index 2ceca0d..144f75d 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -57,6 +57,15 @@ LMSDevice::LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t c
m_last_tx_overruns.resize(chans, 0);
}
+LMSDevice::~LMSDevice()
+{
+ LOGC(DDEV, INFO) << "Closing LMS device";
+ if (m_lms_dev) {
+ LMS_Close(m_lms_dev);
+ m_lms_dev = NULL;
+ }
+}
+
static void lms_log_callback(int lvl, const char *msg)
{
/* map lime specific log levels */
@@ -204,6 +213,7 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
out_close:
LOGC(DDEV, ALERT) << "Error in LMS open, closing: " << LMS_GetLastErrorMessage();
LMS_Close(m_lms_dev);
+ m_lms_dev = NULL;
return -1;
}
diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h
index 6635c13..d1a8813 100644
--- a/Transceiver52M/device/lms/LMSDevice.h
+++ b/Transceiver52M/device/lms/LMSDevice.h
@@ -74,6 +74,7 @@ public:
LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chans, double lo_offset,
const std::vector<std::string>& tx_paths,
const std::vector<std::string>& rx_paths);
+ ~LMSDevice();
/** Instantiate the LMS */
int open(const std::string &args, int ref, bool swap_channels);