Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing on_value_changed callbacks can throw exceptions leading to things not being freed correctly #373

Open
jcelerier opened this issue Dec 13, 2024 · 0 comments

Comments

@jcelerier
Copy link

jcelerier commented Dec 13, 2024

In void PeripheralBase::_cleanup_characteristics() noexcept :

for (auto bluez_characteristic : bluez_service->characteristics()) {

Here:

    frame #0: 0x00007ffff24b0780 libstdc++.so.6`__cxxabiv1::__cxa_throw(obj=0x0000555557107d30, tinfo=0x00007fffcc77c4d8, dest=(libsimpleble-debug.so.0`SimpleDBus::Exception::InterfaceNotFoundException::~InterfaceNotFoundException() at Exceptions.h:36)) at eh_throw.cc:80:1
  * frame #1: 0x00007fffcc7514e3 libsimpleble-debug.so.0`SimpleDBus::Proxy::interface_get(this=0x000055555704fe30, name="org.bluez.GattCharacteristic1") at Proxy.cpp:50:9
    frame #2: 0x00007fffcc720225 libsimpleble-debug.so.0`SimpleBluez::Characteristic::gattcharacteristic1(this=0x000055555704fe30) at Characteristic.cpp:30:59
    frame #3: 0x00007fffcc720e9a libsimpleble-debug.so.0`SimpleBluez::Characteristic::clear_on_value_changed(this=0x000055555704fe30) at Characteristic.cpp:73:49
    frame #4: 0x00007fffcc703ec0 libsimpleble-debug.so.0`SimpleBLE::PeripheralBase::_cleanup_characteristics(this=0x00007fff2c1cc5b0) at PeripheralBase.cpp:309:39
    frame #5: 0x00007fffcc703c31 libsimpleble-debug.so.0`SimpleBLE::PeripheralBase::~PeripheralBase(this=0x00007fff2c1cc5b0) at PeripheralBase.cpp:32:5
    frame #6: 0x00007fffcc7019c5 libsimpleble-debug.so.0`void std::destroy_at<SimpleBLE::PeripheralBase>(__location=0x00007fff2c1cc5b0) at stl_construct.h:88:15

I see exceptions being thrown for for instance org.bluez.GattCharacteristic1, thus

        for (auto bluez_service : device_->services()) {
            for (auto bluez_characteristic : bluez_service->characteristics()) {
                bluez_characteristic->clear_on_value_changed();
            }
        }

if there are multiple services & characteristics, all the following ones will not be cleared :/ I think the catch clause should be inside the innermost for loop, just like for the subsequent loop:

        // Stop notifying all characteristics.
        for (auto bluez_service : device_->services()) {
            for (auto bluez_characteristic : bluez_service->characteristics()) {
                try {
                    if (bluez_characteristic->notifying()) {
                        bluez_characteristic->stop_notify();
                    }
                } catch (std::exception const& e) {
                    SIMPLEBLE_LOG_WARN(fmt::format("Exception during characteristic cleanup: {}", e.what()));
                }
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant