Skip to content

Commit e2fc111

Browse files
committed
Windows: Fix DeRegisterEHFrames from erasing a possibly invalid iterator.
DeRegisterEHFrames can be called without a a prior call to RegisterEHFrames. This can easily be detected so just do nothing when that occurs.
1 parent 1b894b3 commit e2fc111

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Utils/PlatformWin.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,17 @@ void RegisterEHFrames(uintptr_t ImgBs, const EHFrameInfos& Frames, bool Block) {
788788
void DeRegisterEHFrames(uintptr_t ImgBase, const EHFrameInfos& Frames) {
789789
if (Frames.empty())
790790
return;
791-
assert(getImageBaseMap().find(ImgBase) != getImageBaseMap().end());
792791

793-
// Remove the ImageBase from lookup
792+
// There is a chance that DeRegisterEHFrames will without a prior call to
793+
// RegisterEHFrames. Rather than tracking such cases and adding complexity
794+
// just ignore the requests if ImgBase was never registered.
794795
ImageBaseMap& Unwind = getImageBaseMap();
795-
Unwind.erase(Unwind.find(ImgBase));
796+
auto Itr = Unwind.find(ImgBase);
797+
if (Itr == Unwind.end())
798+
return;
799+
800+
// Remove the ImageBase from lookup
801+
Unwind.erase(Itr);
796802

797803
// Unregister all the PRUNTIME_FUNCTIONs
798804
for (auto&& Frame : Frames)

0 commit comments

Comments
 (0)