title: Valgrind Address is on Thread's 1 stack
body: <p>I can't figure out for the life of me what I'm doing wrong.</p>
  
  <pre><code>T* tokenizer = create(argv[1], argv[2]);
  destroy(tokenizer);
  </code></pre>
  
  <p>Here is the structure:</p>
  
  <pre><code>struct T_
  {
      char *sep_set;
      char *str;
      char *token;
      int *last_index;
  };
  typedef struct T_ T;
  </code></pre>
  
  <p>Here is the create function:</p>
  
  <pre><code>T *create(char *separators, char *ts)
  {
      T *tk = malloc(sizeof(struct T_));
      tk-&gt;sep_set = malloc(sizeof(char)*strlen(separators));
      tk-&gt;str = malloc(sizeof(char)*strlen(ts));
      tk-&gt;last_index = malloc(sizeof(int));
      tk-&gt;sep_set = separators;
      tk-&gt;str = ts;
      *tk-&gt;last_index = 0;
      return tk;
  }
  
  void destroy(T *tk)
  {
      free(tk-&gt;sep_set);
      free(tk-&gt;str);
      free(tk-&gt;last_index);
      free(tk);
  }
  </code></pre>
  
  <p>My error is:</p>
  
  <pre><code>==12302== Invalid free() / delete / delete[] / realloc()
  ==12302==    at 0x4C273F0: free (vg_replace_malloc.c:446)
  ==12302==    by 0x400649: destroy (t.c:58)
  ==12302==    by 0x40088C: main (t.c:145)
  ==12302==  Address 0x7ff0006e7 is on thread 1's stack
  ==12302== 
  ==12302== Invalid free() / delete / delete[] / realloc()
  ==12302==    at 0x4C273F0: free (vg_replace_malloc.c:446)
  ==12302==    by 0x400659: destroy (t.c:59)
  ==12302==    by 0x40088C: main (t.c:145)
  ==12302==  Address 0x7ff0006ec is on thread 1's stack
  </code></pre>
  
  <p>Lines 58 and 59 are</p>
  
  <pre><code>free(tk-&gt;sep_set);
  free(tk-&gt;str);
  </code></pre>
  
  <p>Any help would be much appreciated!</p>