Skip to content

Commit

Permalink
src: cleanup the RunCommand queues on RemoveEnv
Browse files Browse the repository at this point in the history
Just to be sure no dangling SharedEnvInst references are left after the
Environment is gone and the EnvInst instance can be deleted.

PR-URL: #25
Reviewed-by: Santiago Gimeno <[email protected]>
  • Loading branch information
santigimeno authored and trevnorris committed Nov 30, 2023
1 parent d67a0ba commit 5e1b2d9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/nsolid/nsolid_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,22 @@ void EnvList::RemoveEnv(Environment* env) {
stor.cb(envinst_sp, stor.data.get());
});

// Cleanup the RunCommand queues just to be sure no dangling SharedEnvInst
// references are left after the Environment is gone and the EnvInst instance
// can be deleted.
EnvInst::CmdQueueStor stor;
while (envinst_sp->eloop_cmds_q_.dequeue(stor)) {
stor.cb(stor.envinst_sp, stor.data);
}

while (envinst_sp->interrupt_cb_q_.dequeue(stor)) {
stor.cb(stor.envinst_sp, stor.data);
}

while (envinst_sp->interrupt_only_cb_q_.dequeue(stor)) {
stor.cb(stor.envinst_sp, stor.data);
}

// Don't allow execution to continue in case a RunCommand() is running in
// another thread since they might need access to Environment specific
// resources (like the Isolate) that won't be valid after this returns.
Expand Down

0 comments on commit 5e1b2d9

Please sign in to comment.