title: Pointer gets lost when allocated struct with pointer on allocated string gets passed as argument for pthread
body: <p>I'm writing a server who starts a thread for each incomming request.
  I want to pass the arugments of the request and some other things to the thread.
  To do so Iam using a struct, which is allocated and contains a pointer which points onto an allocated string. I do so to keep the struct alive for the thread even when the main-thread enters its next loop.
  When I pass the pointer to this struct to my thread, the pointer in the struct which should point onto the string, "lost" its information. 
  Well I get a EXC_BAD_ACCESS and I have no Idea why.</p>
  
  <p>Any help is welcome :-)</p>
  
  <pre><code>typedef struct _thdata
  {
      int socket;
      int thread_no;
      char *parameter;
  }thdata;
  
  void *thread_function(thdata *data)
  {
      printf("Thread %i: got:%s\n",
              data-&gt;thread_no, data-&gt;parameter);&lt;-EXC_BAD_ACCESS
      ...
      free data-&gt;parameter;
      free data;
      pthread_exit((void *)0);
  }
  
  int main(...)
  {   ...
      while(1){
      ...
         thdata *data;
         data = (thdata*)malloc(sizeof(data));
         data-&gt;socket=connSocket;
         data-&gt;thread_no=i;
         data-&gt;parameter=(char*)malloc(strlen(param)+1);
         strcpy(data-&gt;parameter, param);
      ...
         pthread_create( &amp;p_thread, NULL, (void *(*)(void *))thread_function, 
                      (void*) &amp;data);
      ...
      }
  }
  </code></pre>