Visual Studio - how to find source of heap corruption errors

前端 未结 8 1952
失恋的感觉
失恋的感觉 2020-12-02 05:32

I wonder if there is a good way to find the source code that causes a heap corruption error, given the memory address of the data that was written \'outside\' the allocated

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 05:48

    For Window 10 you could enable the PageHeap option in the GFlags Tool, this tool is included as part of the Debugging Tools for Windows.

    The Page Heap options in GFlags lets you select standard heap verification or full-page heap verification. Beware, the full heap verification uses a full page of memory for each allocation so it can cause system memory shortages.

    To enable the Page Heap in GFlags:

    •To enable standard page heap verification, the standard version will write a pattern at the end of each heap allocation and then examine the pattern when the allocations are freed.

    To verify all processes use:

    gflags /r +hpa

    gflags /k +hpa

    for a single process use:

    gflags /p /enable ImageFileName

    •To enable full page heap verification for one process, this option places an inaccessible page at the end of each allocation so that the program stops immediately if it tries to accesses memory beyond the allocation, this should only be used on a single process due to the heavy memory consumption.

    gflags /i ImageFileName +hpa

    gflags /p /enable ImageFileName /full

    The two commands above are interchangeable.

    Note: All page heap settings mentioned above are system wide settings stored in the registry (except /k) and remain effective until you change them. The /k setting is a Kernel flag setting are set for this session and will be lost when Windows shuts down

    Another helpful tool is the Application Verifier, but this is not part of the Debugging Tools for Windows, rather it is included in the Windows Software Development Kit (SDK).

提交回复
热议问题