Skip to content

Commit

Permalink
Instrument MemTracker (#56648)
Browse files Browse the repository at this point in the history
We are seeing some likely memory corruption in
#54469
and these changes hopefully will help better
diagnose it
  • Loading branch information
noahfalk authored Aug 2, 2021
1 parent a190d44 commit d90f6b6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/coreclr/utilcode/loaderheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,21 @@ AllocMemTracker::~AllocMemTracker()
}
}

// We have seen evidence of memory corruption in this data structure.
// https://github.com/dotnet/runtime/issues/54469
// m_pFirstBlock is intended to be a linked list terminating with
// &m_FirstBlock but we are finding a nullptr in the list before
// that point. In order to investigate further we need to observe
// the corrupted memory block(s) before they are deleted below
#ifdef _DEBUG
AllocMemTrackerBlock* pDebugBlock = m_pFirstBlock;
for (int i = 0; pDebugBlock != &m_FirstBlock; i++)
{
CONSISTENCY_CHECK_MSGF(i < 10000, ("Linked list is much longer than expected, memory corruption likely\n"));
CONSISTENCY_CHECK_MSGF(pDebugBlock != nullptr, ("Linked list pointer == NULL, memory corruption likely\n"));
pDebugBlock = pDebugBlock->m_pNext;
}
#endif

AllocMemTrackerBlock *pBlock = m_pFirstBlock;
while (pBlock != &m_FirstBlock)
Expand Down

0 comments on commit d90f6b6

Please sign in to comment.