summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-19 13:21:08 +0200
committerSven Gothel <[email protected]>2020-10-19 13:21:08 +0200
commite84963b9bb7bd383dd7f8bbb08b261d247b0332f (patch)
treec0814937f9a5dd8f3aa53736ee81a5fcde3fa498 /src
parent75b1bb70467e68ed4f98cf2d9f177b28cc868379 (diff)
DBTDevice::dtor: Don't recurse back into remove() -> adapter removeDevice(), that is how it potentially has been deleted!
This fix also gives us the opportunity back to use a simple mutex for mtx_sharedDevices. Also add dedicated close() for better leak testing.
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/DBTAdapter.cpp24
-rw-r--r--src/direct_bt/DBTDevice.cpp1
2 files changed, 15 insertions, 10 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index 198dd8f2..5f90279c 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -225,6 +225,12 @@ DBTAdapter::DBTAdapter(const int _dev_id) noexcept
DBTAdapter::~DBTAdapter() noexcept {
DBG_PRINT("DBTAdapter::dtor: ... %p %s", this, toString().c_str());
+ close();
+ DBG_PRINT("DBTAdapter::dtor: XXX");
+}
+
+void DBTAdapter::close() noexcept {
+ DBG_PRINT("DBTAdapter::close: ... %p %s", this, toString().c_str());
keepDiscoveringAlive = false;
// mute all listener first
{
@@ -235,9 +241,9 @@ DBTAdapter::~DBTAdapter() noexcept {
poweredOff();
- DBG_PRINT("DBTAdapter::dtor: closeHCI: ...");
+ DBG_PRINT("DBTAdapter::close: closeHCI: ...");
hci.close();
- DBG_PRINT("DBTAdapter::dtor: closeHCI: XXX");
+ DBG_PRINT("DBTAdapter::close: closeHCI: XXX");
{
const std::lock_guard<std::mutex> lock(mtx_discoveredDevices); // RAII-style acquire and relinquish via destructor
@@ -248,10 +254,10 @@ DBTAdapter::~DBTAdapter() noexcept {
connectedDevices.clear();;
}
{
- const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
sharedDevices.clear();
}
- DBG_PRINT("DBTAdapter::dtor: XXX");
+ DBG_PRINT("DBTAdapter::close: XXX");
}
void DBTAdapter::poweredOff() noexcept {
@@ -271,7 +277,7 @@ void DBTAdapter::poweredOff() noexcept {
void DBTAdapter::printSharedPtrListOfDevices() noexcept {
{
- const std::lock_guard<std::recursive_mutex> lock0(mtx_sharedDevices);
+ const std::lock_guard<std::mutex> lock0(mtx_sharedDevices);
jau::printSharedPtrList("SharedDevices", sharedDevices);
}
{
@@ -621,7 +627,7 @@ std::vector<std::shared_ptr<DBTDevice>> DBTAdapter::getDiscoveredDevices() const
}
bool DBTAdapter::addSharedDevice(std::shared_ptr<DBTDevice> const &device) noexcept {
- const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
if( nullptr != findDevice(sharedDevices, *device) ) {
// already shared
return false;
@@ -631,12 +637,12 @@ bool DBTAdapter::addSharedDevice(std::shared_ptr<DBTDevice> const &device) noexc
}
std::shared_ptr<DBTDevice> DBTAdapter::getSharedDevice(const DBTDevice & device) noexcept {
- const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
return findDevice(sharedDevices, device);
}
void DBTAdapter::removeSharedDevice(const DBTDevice & device) noexcept {
- const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
for (auto it = sharedDevices.begin(); it != sharedDevices.end(); ) {
if ( nullptr != *it && device == **it ) {
it = sharedDevices.erase(it);
@@ -648,7 +654,7 @@ void DBTAdapter::removeSharedDevice(const DBTDevice & device) noexcept {
}
std::shared_ptr<DBTDevice> DBTAdapter::findSharedDevice (EUI48 const & mac, const BDAddressType macType) noexcept {
- const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
return findDevice(sharedDevices, mac, macType);
}
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index 57fe251c..1e3ddfd8 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -74,7 +74,6 @@ DBTDevice::DBTDevice(DBTAdapter & a, EInfoReport const & r)
DBTDevice::~DBTDevice() noexcept {
DBG_PRINT("DBTDevice::dtor: ... %p %s", this, getAddressString().c_str());
- remove();
advServices.clear();
advMSD = nullptr;
DBG_PRINT("DBTDevice::dtor: XXX %p %s", this, getAddressString().c_str());