title: How to solve ntdll.dll!RtlpLogHeapFailure() in Visual Studio 2015?
body: <p>I am currently working on an AI project. It's about that puzzle you need to move the board pieces numbered from 1 to 8 (and the empty space is labelled as 0) in order to let it sorted at the end.
  However I got a weird problem when I try to debug it.</p>
  
  <pre><code>int CreateNewState(State *parent, Action action) {
  State *newState;
  
      if (!(newState = (State*)malloc(sizeof(State)))) // &lt;&lt;&lt;&lt; Error
         return 0;
  ...
  
     // Populate my newState
     newState-&gt;parent = parent;
     newState-&gt;matrix = CreateMatrix();
  ...
     // Insert my newState in the Queue
     Insert(newState, myMode);
  }
  
  
  void Insert(State *state, Mode mode) {
     State *aux;
  
      if (IsEmpty()) {
          myQueue-&gt;firstState = state;
          myQueue-&gt;numberOfElements++;
      }
      else {
          aux = myQueue-&gt;firstState;
  
          switch (mode)
          {
              // Breadth First Search
              case BFS:
                  while (aux-&gt;next != NULL) {
                     aux = aux-&gt;next;
                  }
                  aux-&gt;next = state;
                  myQueue-&gt;numberOfElements++;
                  break;
             ...
  
          }
      }
  }
  </code></pre>
  
  <p>In the specified Error comment, when I call the CreateNewState() function for the second time, the Debugger stops and popups: </p>
  
  <blockquote>
    <p>AIProject_Puzzle.exe has triggered a breakpoint.</p>
  </blockquote>
  
  <p>I tried to bring you guys some additional information in the Call Stack when this error occurs:</p>
  
  <blockquote>
    <p>ntdll.dll!RtlReportCriticalFailure()<br>
        ntdll.dll!RtlpHeapHandleError()<br>
        ntdll.dll!RtlpLogHeapFailure()<br>
        ntdll.dll!RtlpAllocateHeap()<br>
        ntdll.dll!RtlAllocateHeap()<br>
        ucrtbased.dll!00007ff9b582c4da()<br>
        ucrtbased.dll!00007ff9b582c27d()<br>
        ucrtbased.dll!00007ff9b582f34f()<br>
        ucrtbased.dll!00007ff9b582fdde()<br>
      AIProject_Puzzle.exe!CreateNewState(state * parent=0x000000c05c273520, action action=DOWN)</p>
  </blockquote>
  
  <p>I know it might be a Heap corruption so, what I really need it is a clue in order to solve this.
  I am using Visual Studio Community 2015, VisualC++.
  This error is making me sick. Please could anyone know how to solve this issue?</p>