Skip to content

Commit 2dbb826

Browse files
santigimenotrevnorris
authored andcommitted
src: cleanup the RunCommand queues on RemoveEnv
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: Trevor Norris <trev.norris@gmail.com>
1 parent 5ab8629 commit 2dbb826

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/nsolid/nsolid_api.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,22 @@ void EnvList::RemoveEnv(Environment* env) {
989989
stor.cb(envinst_sp, stor.data.get());
990990
});
991991

992+
// Cleanup the RunCommand queues just to be sure no dangling SharedEnvInst
993+
// references are left after the Environment is gone and the EnvInst instance
994+
// can be deleted.
995+
EnvInst::CmdQueueStor stor;
996+
while (envinst_sp->eloop_cmds_q_.dequeue(stor)) {
997+
stor.cb(stor.envinst_sp, stor.data);
998+
}
999+
1000+
while (envinst_sp->interrupt_cb_q_.dequeue(stor)) {
1001+
stor.cb(stor.envinst_sp, stor.data);
1002+
}
1003+
1004+
while (envinst_sp->interrupt_only_cb_q_.dequeue(stor)) {
1005+
stor.cb(stor.envinst_sp, stor.data);
1006+
}
1007+
9921008
// Don't allow execution to continue in case a RunCommand() is running in
9931009
// another thread since they might need access to Environment specific
9941010
// resources (like the Isolate) that won't be valid after this returns.

0 commit comments

Comments
 (0)