title: Malloc cause memory leak
body: <p>I have the following code. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #define _CRTDBG_MAP_ALLOC
  #include &lt;stdlib.h&gt;
  #include &lt;crtdbg.h&gt;
  
  int main(){
     int *N=NULL;
     char *S=NULL,input[50],*Par=NULL,T='^';
     printf("Give me the equation: ");
     scanf("%s",input);
     printf("\n%d",strlen(input));
     S=(char*)malloc(3);
     N=(int*)malloc((strlen(input)-3)*sizeof(int));
     _CrtDumpMemoryLeaks();  /* Memory leak detected! */
     free(S);
     free(N);
     return 0;
  }
  </code></pre>
  
  <p>After malloc returns without a problem the function in the line with the comment prints in the output window in visual studio the next message:</p>
  
  <pre><code>Detected memory leaks!
  Dumping objects -&gt;
  c:\users\manos\documents\visual studio 2010\projects\gcjgcjc\gcjgcjc\gdjjj.cpp(17) : {60} normal block at 0x00A343F8, 16 bytes long.
  Data: &lt;                &gt; CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
  c:\users\manos\documents\visual studio 2010\projects\gcjgcjc\gcjgcjc\gdjjj.cpp(16) : {59} normal block at 0x00A31B30, 3 bytes long.
  Data: &lt;   &gt; CD CD CD 
  Object dump complete.
  </code></pre>
  
  <p>When the program stops the visual detects heap corruption.
  Does anyone know what happens? As far as i know there's nothing wrong with my code so what happens with malloc? Did i do something that caused the memory leak?</p>