title: Memory leak question in C after moving pointer (What exactly is deallocated?)
body: <p>I realize the code sample below is something you should never do. My question is just one of interest. If you allocate a block of memory, and then move the pointer (a no-no), when you deallocate the memory, what is the size of the block that is deallocated, and where is it in memory? Here's the contrived code snippet: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(void) {
      char* s = malloc(1024);
      strcpy(s, "Some string");
      // Advance the pointer...
      s += 5;
      // Prints "string"
      printf("%s\n", s);
      /*
       * What exactly are the beginning and end points of the memory 
       * block now being deallocated?
       */
      free(s);
      return 0;
  }
  </code></pre>
  
  <p>Here is what I think I happens. The memory block being deallocated begins with the byte that holds the letter "s" in "string". The 5 bytes that held "Some " are now lost. </p>
  
  <p>What I'm wondering is: Are the 5 bytes whose location in memory immediately follows the end of the original 1024 bytes deallocated as well, or are they just left alone?</p>
  
  <p>Anyone know for sure what is it the compiler does? Is it undefined? </p>
  
  <p>Thanks.</p>