# HG changeset patch # User rubidium # Date 1209939227 0 # Node ID 4887c2e470e47556ec8ada949ebb0efbf4b976b1 # Parent 8b3897a75aed644e6e92389dbf0b2ed4dd585ce1 (svn r12945) -Fix: (small) memory leak when joining/exiting threads. diff -r 8b3897a75aed -r 4887c2e470e4 src/thread_pthread.cpp --- a/src/thread_pthread.cpp Sun May 04 21:53:36 2008 +0000 +++ b/src/thread_pthread.cpp Sun May 04 22:13:47 2008 +0000 @@ -104,6 +104,8 @@ pthread_join(m_thr, &ret); m_thr = 0; + delete this; + return ret; } @@ -136,16 +138,22 @@ /* The new thread stops here so the calling thread can complete pthread_create() call */ sem_wait(&m_sem_start); + /* Did this thread die naturally/via exit, or did it join? */ + bool exit = false; + /* Call the proc of the creator to continue this thread */ try { m_proc(m_param); } catch (...) { + exit = true; } /* Notify threads waiting for our completion */ sem_post(&m_sem_stop); - return NULL; + if (exit) delete this; + + pthread_exit(NULL); } };