What KERNEL_MODE_HEAP_CORRUPTION means

Bug check 0x13A means the kernel-mode heap manager detected corruption in a heap. Microsoft’s reference describes the first parameter as the type of corruption, such as a buffer overrun, a buffer underrun, a block used after it was freed, or a corrupted free list. All of these usually trace back to code that wrote outside the memory it owned, which is why drivers are the first suspect.

Common causes

  • A driver that writes past the end of, or before the start of, a memory block
  • A driver that uses memory after releasing it, or releases it twice
  • Recently installed or updated drivers, especially after hardware changes
  • Faulty RAM or unstable memory settings that corrupt data in memory

How to fix KERNEL_MODE_HEAP_CORRUPTION

Work through these in order and test after each one. Stopping as soon as the crashes stop tells you which change mattered.

  1. Undo the most recent change. If the blue screens began after a Windows update, a new driver or new software, remove that change first. Uninstall the update from Settings, Windows Update, Update history, or roll a driver back in Device Manager (right-click the device, Properties, Driver, Roll Back Driver). Heap corruption often begins right after hardware or drivers change.
  2. Note the file name on the blue screen. If the screen shows a line such as "What failed" followed by a .sys file, write it down. Searching that file name shows which driver it belongs to, which tells you what to update or remove. The named file is the code that crashed, which is not always the root cause.
  3. Return the PC to stock settings. Reset the BIOS to defaults, then leave XMP or EXPO, CPU or GPU overclocks and undervolts (including per-core offsets such as Curve Optimizer) switched off while you test. If the crashes stop, re-enable one setting at a time to find the unstable one.
  4. Test the memory. Run Windows Memory Diagnostic (search for it in Start) for a quick check, then MemTest86 for several passes if the crashes continue. Any error points to a faulty stick or slot, or to memory settings the hardware cannot run reliably.
  5. Repair Windows system files. Open Terminal (Admin) and run sfc /scannow. If it reports damage it could not repair, run DISM /Online /Cleanup-Image /RestoreHealth, restart, and run sfc /scannow once more.

Reading the crash evidence for 0x13A

Microsoft’s reference gives the first parameter as the type of heap corruption, the second as the heap that reported it, and the third as the address where it was detected. The first parameter is the one to note, because it tells you how the heap was damaged.

Windows normally saves a small dump in C:\Windows\Minidump. If several crashes show the same first parameter and the same driver on the stack, that driver is the leading suspect.

Some first-parameter values for 0x13A documented by Microsoft
First parameterWhat Microsoft describesWhat it suggests
0x3 or 0x4One or more corrupt entry headersMemory was overwritten near a block
0x6Corruption consistent with a buffer overrunCode wrote past the end of a block
0x7Corruption consistent with a buffer underrunCode wrote before the start of a block
0xBError consistent with using a block after freeing itUse after free
0xDA corrupt free list, possibly use after free or an overflow of a nearby blockMemory misuse by a driver
0x13The heap routine was passed a NULL heap handleA driver calling the heap with a bad handle

Source: Microsoft Learn: Bug Check 0x13A KERNEL_MODE_HEAP_CORRUPTION ↗

When to stop and protect your data

If the crashes continue after a clean memory test and a driver review, keep the minidump. A debugger can show the first parameter and the call stack, which names the code performing the faulty heap operation.

Not sure this is your code?

The stop code appears as text on the blue screen. If the PC restarted before you could read it, open Event Viewer, then Windows Logs, then System, and look for a BugCheck event with ID 1001. You can also search all stop codes.

Related guides

Other system file and kernel errors