locked
Tips on debugging heap related issues RRS feed

  • Question

  • I have a program written in C++ and compiled using Visual C++ 2012 (yes I know its old but there are reasons we still use 2012 for this particular version of the program that I won't go into here). We have been getting crashdumps from some of our users where the crash point is somewhere in the Windows memory manager in ntdll.dll with the call stack featuring Windows memory manager stuff then MS CRT memory management bits then our own memory stuff then various bits of other code in our program (its not the same every time, its different) I have seen this happen on both allocate and free calls.

    The best guess is that we have some sort of heap corruption issues somewhere. (already ruled out out-of-memory issues as the cause and enough people are having the same issue that its unlikely to be a hardware failure) Are there any tools or tricks or things we can use to help track down where the heap corruption is actually occurring? Some sort of heap validation setup we can have the users experiencing the crashes run that will pick up issues when they happen and help us find the  cause?

    Thursday, November 21, 2019 9:29 AM

All replies

  • Thursday, November 21, 2019 9:38 AM
  • Are there any tools or tricks or things we can use to help track down where the heap corruption is actually occurring? Some sort of heap validation setup we can have the users experiencing the crashes run that will pick up issues when they happen and help us find the  cause?

    You could use a version of the application that uses the heap validation capabilities of the debug heap.  From the VS "previous version" docs -

    https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/wxex5fzd(v=vs.100)

    _CRTDBG_CHECK_ALWAYS_DF

    Causes _CrtCheckMemory to be called at every allocation and deallocation. This slows execution, but catches errors quickly.

    -------------

    Alternatively, the application could include calls to  _CrtCheckMemory at specific points in the code whenever you want to validate the heap to help identify corruption.


    • Edited by RLWA32 Thursday, November 21, 2019 10:41 AM
    Thursday, November 21, 2019 10:41 AM
  • One more tool that you can use is the "gflags"/"global flags".  You shoudl check "Enable page heap"  after entering your application name in the edit box. After you click "Apply", then run your application and try out various workflows that you suspect may result in heap corruption.

    -Seetharam


    • Edited by Seetharam Thursday, November 21, 2019 9:57 PM
    Thursday, November 21, 2019 9:56 PM
  • Hello,

    Do you resolve the issue? If you resolve the issue, please "Mark as answer" or "Vote as helpful" post to the appropriate answer, so that it will help other members to find solution quickly if they faces similar issue. If not, please feel free to contact us.

    Best Regards,

    Suarez Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 26, 2019 1:41 AM