<p>Suppose I have the following code:</p>

<pre><code>while(TRUE) {
  pthread_t *thread = (pthread_t *) malloc(sizeof(pthread_t));
  pthread_create(thread, NULL, someFunction, someArgument);
  pthread_detach(*thread);
  sleep(10);
}
</code></pre>

<p>Will the detached thread free the memory allocated by malloc, or is that something I now have to do?</p>

No.
pthread_create()
has no way of knowing that the
thread
pointer passed to it was dynamically allocated. pthreads doesn't use this value internally; it simply returns the new thread id to the caller. You don't need to dynamically allocate that value; you can pass the address of a local variable instead:
```
```
pthread_t thread;
pthread_create(&thread, NULL, someFunction, someArgument);
```
```