title: Heap corruption while trying to free a wchar_t pointer
body: <p>This is a code that evaluates if a wide string is either L"false" or L"true", but when I try to run it, it gives me this error when trying to free the duplicate string pointer "HEAP CORRUPTION DETECTED: after Normal block(#135756) at 0x00000000002EB3A0. CRT detected that the application wrote to memory after end of heap buffer.".</p>
  
  <p>Here is the inline code:</p>
  
  <pre><code>const wchar_t* sequence = L"false";
  
  wchar_t* duplicate;
  size_t length = wcslen(sequence) + 1;
  
  duplicate = static_cast&lt;wchar_t*&gt;(malloc(length));
  
  wcscpy_s(duplicate, length, sequence);
  
  int boolean = -1;
  
  if (wcscmp(duplicate, L"false") == 0) {
      boolean = 0;
  }
  else if (wcscmp(duplicate, L"true") == 0) {
      boolean = 1;
  }
  
  free(duplicate);
  </code></pre>
  
  <p>All the string pointers seem to be OK right before the free statement. I am sure I have done some serious mistake simply because I was able to corrupt the heap.</p>
  
  <p>Compiler: Microsoft Visual Studio 2015 RC</p>
  
  <p>Processor: Inter Core i5-3450 3.10 GHz</p>