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:
@@ -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()) {
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
~SingleSourceSubscriptionCtx() {
|
||||
assert(!eventsEnabled);
|
||||
// must db_cancel_event() before ~MonitorControlOp
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user