Skip to content

Commit

Permalink
droid.cpp: Fix DROID dtor segfault for transports
Browse files Browse the repository at this point in the history
When a transport has some droids in it while
its dtor is being called, the code that frees
all droids in its transport group will segfault
because each `delete psCurr` will modify the list
and hence invalidate the current iterator.

Signed-off-by: Pavel Solodovnikov <[email protected]>
  • Loading branch information
ManManson committed Jan 6, 2024
1 parent 794aef9 commit 42d3c12
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,16 @@ DROID::~DROID()
if (psDroid->psGroup)
{
//free all droids associated with this Transporter
for (DROID* psCurr : psDroid->psGroup->psList)
mutating_list_iterate(psDroid->psGroup->psList, [psDroid](DROID* psCurr)
{
if (psCurr == psDroid)
{
break;
return IterationResult::BREAK_ITERATION;
}
// This will cause each droid to self-remove from `psGroup->psList`.
delete psCurr;
}
return IterationResult::CONTINUE_ITERATION;
});
}
}

Expand Down

0 comments on commit 42d3c12

Please sign in to comment.