title: Memory Leak when freeing a char array
body: <p>I have malloc a char array and initialize it:</p>
  
  <pre><code>int i;
  int length = 100;
  char *arr = (char *) malloc (length * sizeof(char));
  for (i = 0; i &lt; length; i++) {
      arr[i] = i;
  }
  </code></pre>
  
  <p>then I set the middle char to '\0':</p>
  
  <pre><code>arr[50] = '\0';
  </code></pre>
  
  <p>In this case, arr only has invalid length 50, not 100
  then I use free:</p>
  
  <pre><code>free(arr);
  </code></pre>
  
  <p>can this cause memory leak? ie the operating system will record the malloc length or just use strlen to judge the length?</p>