Skip to content

Commit 56e11e9

Browse files
committed
src: avoid accessing EnvInst on Env destruction
1 parent 156ce89 commit 56e11e9

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

src/nsolid/nsolid_api.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,16 @@ void EnvList::PromiseTracking(bool promiseTracking) {
13521352
}
13531353

13541354
for (auto& entry : env_map) {
1355-
EnvInst* envinst = entry.second.get();
1356-
if (envinst->env()->nsolid_track_promises_fn().IsEmpty())
1355+
SharedEnvInst envinst_sp = entry.second;
1356+
EnvInst::Scope lock(envinst_sp);
1357+
if (!lock.Success())
1358+
continue;
1359+
1360+
if (envinst_sp->env()->nsolid_track_promises_fn().IsEmpty())
13571361
continue;
13581362

13591363
int er = EnvInst::RunCommand(
1360-
EnvInst::GetInst(envinst->thread_id()),
1364+
envinst_sp,
13611365
promiseTracking ? enable_promise_tracking_ : disable_promise_tracking_,
13621366
nullptr,
13631367
CommandType::InterruptOnly);
@@ -1389,8 +1393,12 @@ void EnvList::UpdateTracingFlags(uint32_t flags) {
13891393
}
13901394

13911395
for (auto& entry : env_map) {
1392-
SharedEnvInst envinst = entry.second;
1393-
int er = RunCommand(envinst,
1396+
SharedEnvInst envinst_sp = entry.second;
1397+
EnvInst::Scope lock(envinst_sp);
1398+
if (!lock.Success())
1399+
continue;
1400+
1401+
int er = RunCommand(envinst_sp,
13941402
CommandType::InterruptOnly,
13951403
update_tracing_flags,
13961404
flags);
@@ -2053,8 +2061,12 @@ void EnvList::UpdateHasMetricsStreamHooks(bool has_metrics) {
20532061
}
20542062

20552063
for (auto& entry : env_map) {
2056-
SharedEnvInst envinst = entry.second;
2057-
int er = RunCommand(envinst,
2064+
SharedEnvInst envinst_sp = entry.second;
2065+
EnvInst::Scope lock(envinst_sp);
2066+
if (!lock.Success())
2067+
continue;
2068+
2069+
int er = RunCommand(envinst_sp,
20582070
CommandType::InterruptOnly,
20592071
update_has_metrics_stream_hooks,
20602072
has_metrics);

0 commit comments

Comments
 (0)