title: Using strtok() on an allocated string?
body: <p>Is there anything I should know about using strtok on a malloced string?</p>
  
  <p>In my code I have (in general terms)</p>
  
  <pre><code>char* line=getline();
  Parse(dest,line);
  free(line);
  </code></pre>
  
  <p>where <code>getline()</code> is a function that returns a char * to some malloced memory.
  and <code>Parse(dest, line)</code> is a function that does parsing online, storing the results in <code>dest</code>, (which has been partially filled earlier, from other information).</p>
  
  <p><code>Parse()</code> calls <code>strtok()</code> a variable number of times on line, and does some validation.
  Each token (a pointer to what is returned by <code>strtok()</code>) is put into a queue 'til I know how many I have.</p>
  
  <p>They are then copied onto a malloc'd char** in dest.</p>
  
  <p>Now <code>free(line)</code>
  and a function that free's each part of the char*[] in dest, both come up on valgrind as:</p>
  
  <blockquote>
    <p>"Address 0x5179450 is 8 bytes inside a block of size 38 free'd"</p>
  </blockquote>
  
  <p>or something similar.</p>
  
  <p>I'm considering refactoring my code not to directly store the tokens on the the char** but instead store a copy of them (by mallocing space == to strlen(token)+1, then using <code>strcpy()</code>).</p>