Skip to content

Commit 404e9a1

Browse files
committed
refactor: capture weak_ptr to State in Conditions callbacks
1 parent 38e192b commit 404e9a1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

libs/server-sdk/src/data_systems/fdv2/conditions.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ Conditions::Conditions(std::vector<std::unique_ptr<IFDv2Condition>> conditions)
137137
: conditions_(std::move(conditions)), state_(std::make_shared<State>()) {
138138
MakeAggregateFuture(conditions_)
139139
.Then(
140-
[state =
141-
state_](IFDv2Condition::Type const& type) -> std::monostate {
140+
[weak_state = std::weak_ptr<State>(state_)](
141+
IFDv2Condition::Type const& type) -> std::monostate {
142+
auto state = weak_state.lock();
143+
if (!state) {
144+
return {};
145+
}
142146
std::vector<PendingEntry> drained;
143147
{
144148
std::lock_guard lock(state->mutex);
@@ -177,7 +181,11 @@ async::Future<IFDv2Condition::Type> Conditions::GetFuture(
177181
// callback fires synchronously inside the ctor and needs to acquire
178182
// state_->mutex.
179183
auto cb = std::make_unique<async::CancellationCallback>(
180-
token, [state = state_, id]() {
184+
token, [weak_state = std::weak_ptr<State>(state_), id]() {
185+
auto state = weak_state.lock();
186+
if (!state) {
187+
return;
188+
}
181189
std::lock_guard lock(state->mutex);
182190
state->pending.erase(
183191
std::remove_if(

0 commit comments

Comments
 (0)