Note that there are some explanatory texts on larger screens.

plurals
  1. PODetached pthread_create() leaks memory
    primarykey
    data
    text
    <p>I'm developping an application in C in a Linux environment. I've noticed that the following code leaks tons of memory after only hundreds executions :</p> <pre><code>do { pthread_t flushThread; pthread_attr_t attr; logevent_thread_t logThread = { Db , &amp;do_curl }; if (( pthread_attr_init ( &amp;attr ) == 0 ) &amp;&amp; ( pthread_attr_setdetachstate ( &amp;attr , PTHREAD_CREATE_DETACHED ) == 0 ) ) { pthread_create ( &amp;flushThread , &amp;attr , (void*)FlushThread , (void*)&amp;logThread ); pthread_attr_destroy ( &amp;attr ); } } while(1); </code></pre> <p>When I started with the code, I only used pthread_create(), but when I noticed the leak, I started google'd and searched StackOverflow, and found the following URLs :</p> <ul> <li><a href="https://stackoverflow.com/questions/3098655/pthread-create-memory-leak">pthread_create memory leak</a></li> <li><a href="https://stackoverflow.com/questions/5610677/valgrind-memory-leak-errors-when-using-pthread-create">valgrind memory leak errors when using pthread_create</a></li> </ul> <p>That's why I initialize the attributes and start the thread "detached". I also destroy the attributes. I can not use pthread_join() since I don't want a blocking call, I want my thread to live on his own.</p> <p>Unfortunately, the leak is still there. I've no more ideas, and will get any further advice !</p> <p>Thank you !</p> <hr> <p>@arrowdodger: Calling pthread_detach() without setting any kind of attributes also leaks. I also tried with setdetach and pthread_detach() without success.</p> <p>@drhirsch : I know it leaks because when I have it run for 1 day, I get a "Out Of Memory" kernel panic. Additionnaly, using top I can see more and more memoery dedicated to my process (but I understand the best way to minitor this is to use valgrind).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload