title: VirtualFree with bad pointer
body: <p>According to documentation first parameter of VirtualFree should be the same as pointer returned by VirtualAlloc:</p>
  
  <blockquote>
    <p>If the dwFreeType parameter is MEM_RELEASE, this parameter must be the
    base address returned by the VirtualAlloc function when the region of
    pages is reserved.</p>
  </blockquote>
  
  <p>Looking at my code below, function VirtualFree can also success when I add offset 0 - FFF (0 - 4095).</p>
  
  <p>Why is such call of VirtualFree not failing? Code below.</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  void main() 
  {
      size_t size = 4*4096;
  
      VOID* ptr = (VOID*)VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
      if (!ptr)
      {
          printf("VirtualAlloc failed with status %lu\n", GetLastError());
          return;
      }
      else
      {
          printf("Pointer = %p\n", ptr);
      }
  
      printf("          ");
      scanf("%p", (VOID*)&amp;ptr);
      printf("pointer = %p\n", ptr);
  
      BOOL status = VirtualFree(ptr, 0, MEM_RELEASE); 
      if (!status)
      {
          printf("VirtualFree failed with status %lu\n", GetLastError());
      }
      else
      {
          printf("VirtualFree success\n");
      }
  
      getchar();
      return;
  }
  </code></pre>