source/base: Only disable the event if it exists
This shouldn't happen in practice but will be needed to supporting
moving.
diff --git a/src/sdeventplus/source/base.cpp b/src/sdeventplus/source/base.cpp
index cab2c7a..3e164ca 100644
--- a/src/sdeventplus/source/base.cpp
+++ b/src/sdeventplus/source/base.cpp
@@ -15,7 +15,10 @@
Base::~Base()
{
- set_enabled(SD_EVENT_OFF);
+ if (source)
+ {
+ set_enabled(SD_EVENT_OFF);
+ }
}
int Base::prepareCallback()
diff --git a/test/source/base.cpp b/test/source/base.cpp
index 3b6a63f..c9b248f 100644
--- a/test/source/base.cpp
+++ b/test/source/base.cpp
@@ -93,6 +93,16 @@
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
}
+TEST_F(BaseTest, NoSource)
+{
+ EXPECT_CALL(mock, sd_event_ref(expected_event))
+ .WillOnce(Return(expected_event));
+ BaseImpl source(*event, nullptr, std::false_type());
+
+ EXPECT_CALL(mock, sd_event_source_unref(nullptr)).WillOnce(Return(nullptr));
+ EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
+}
+
class BaseMethodTest : public BaseTest
{
protected: