title: Why can't Application Verifier find memory leaks?
body: <p>I'm using Windows 10 Application Verifier, x64 version 10.0.10586. It has all the "Basics" checkboxes ticked, including "Leak". Application Verifier curiously is implementing a page protected heap for the memory, as the malloc call returns memory at the end of a page.</p>
  
  <p>DLL code:</p>
  
  <pre><code>extern "C" __declspec(dllexport) void LeakMemory()
  {
      malloc(1);
      VirtualAlloc(nullptr, 4096, MEM_COMMIT, PAGE_READWRITE);
  }
  </code></pre>
  
  <p>main code:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;crtdbg.h&gt;
  
  int main(int, char**)
  {
      //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  
      HMODULE h = LoadLibraryW(L"DLLProject.dll");
      void(*pLeakMemory)() = reinterpret_cast&lt;void(*)()&gt;(GetProcAddress(h, "LeakMemory"));
      pLeakMemory();
      FreeLibrary(h);
  
      printf("bye\n");
      return 0;
  }
  </code></pre>
  
  <p>Output is as follows:</p>
  
  <pre><code>Page heap: pid 0xFE8: page heap enabled with flags 0x3.
  AVRF: ConsoleApplication4.exe: pid 0xFE8: flags 0x81643027: application verifier enabled
  bye
  The program '[11172] TestProject.exe' has exited with code 0 (0x0).
  </code></pre>
  
  <p>App verifier fails to report either of the leaks.</p>
  
  <p>If I enable the _CrtDbgFlag call then verifies that in fact the malloc leaked by also printing this on app shutdown:</p>
  
  <pre><code>Detected memory leaks!
  Dumping objects -&gt;
  {74} normal block at 0x0000015C0979EFF0, 1 bytes long.
   Data: &lt; &gt; CD 
  Object dump complete.
  </code></pre>
  
  <p>Why doesn't Application Verifier work? It also fails to find leaks if I allocate memory in main() instead of a DLL, but I think that's a known limitation of it.</p>