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 authored and KJeff01 committed Jan 6, 2024
1 parent 22b0518 commit 025764d
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 025764d

Please sign in to comment.