title: Heap Corruption Detected: after Normal block
body: <p>"CRT detected that the application wrote to memory end of heap buffer" error. It crashes when it arrives to <code>free</code>. Any help is appreciated.</p>
  
  <pre><code>int messageFunction(char* message) {
     char* sPtr = strstr(message,"Subject:");
     char* cPtr = strstr(message,"Content:");
  
     char* messageSubject = (char*) malloc(cPtr - sPtr - strlen("Subject:"))
     char* messageContent = (char*) malloc(strlen(cPtr + strlen("Content:")))
  
     strncpy(messageSubject, 
            stPtr + strlen("Subject:"), 
            cPtr - sPtr - strlen("Subject:"));
  
     messageSubject[cPtr - sPtr - strlen("Subject:")] = '\0';
  
     strncpy(messageContent, 
             cPtr + strlen("Content:"), 
             strlen(cPtr + strlen("Content:")));
     ...
     free(messageSubject);
     free(messageContent);
     }
  
  
  void main() {
    char* message = "Subject:HelloWorldContent:MessageContent";
    int result = messageFunction(message);
   }
  </code></pre>