ioc: ensure db_cancel_event() before ~MonitorControlOp

previously, ~SingleSourceSubscriptionCtx would ~MonitorControlOp
before the base class ~SubscriptionCtx would db_cancel_event()
leading to a use-after-free.
This commit is contained in:
Michael Davidsaver
2023-09-12 19:11:10 +02:00
parent 68cc69b984
commit ec0b21d27c
3 changed files with 10 additions and 0 deletions
+1
View File
@@ -37,6 +37,7 @@ public:
// This is so that we can merge this with the subsequent values that come in before all initial events are in
Value currentValue;
// must db_cancel_event() before ~MonitorControlOp
std::vector<FieldSubscriptionCtx> fieldSubscriptionContexts{};
explicit GroupSourceSubscriptionCtx(Group& subscribedGroup)
:group(subscribedGroup), currentValue(subscribedGroup.valueTemplate.cloneEmpty()) {
+2
View File
@@ -51,6 +51,8 @@ public:
~SingleSourceSubscriptionCtx() {
assert(!eventsEnabled);
// must db_cancel_event() before ~MonitorControlOp
cancel();
}
};
+7
View File
@@ -45,6 +45,9 @@ public:
if(!sub)
throw std::runtime_error("Failed to create db subscription");
}
void cancel() {
sub.reset();
}
void enable() {
if(sub) {
db_event_enable(sub.get());
@@ -67,6 +70,10 @@ public:
Subscription pPropertiesEventSubscription;
bool hadValueEvent = false;
bool hadPropertyEvent = false;
void cancel() {
pValueEventSubscription.cancel();
pPropertiesEventSubscription.cancel();
}
};
} // ioc