1
0
Fork 0

(svn r12945) -Fix: (small) memory leak when joining/exiting threads.

release/0.7
rubidium 2008-05-04 22:13:47 +00:00
parent 297f99e100
commit 7a85e26268
1 changed files with 9 additions and 1 deletions

View File

@ -104,6 +104,8 @@ public:
pthread_join(m_thr, &ret); pthread_join(m_thr, &ret);
m_thr = 0; m_thr = 0;
delete this;
return ret; return ret;
} }
@ -136,16 +138,22 @@ private:
/* The new thread stops here so the calling thread can complete pthread_create() call */ /* The new thread stops here so the calling thread can complete pthread_create() call */
sem_wait(&m_sem_start); 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 */ /* Call the proc of the creator to continue this thread */
try { try {
m_proc(m_param); m_proc(m_param);
} catch (...) { } catch (...) {
exit = true;
} }
/* Notify threads waiting for our completion */ /* Notify threads waiting for our completion */
sem_post(&m_sem_stop); sem_post(&m_sem_stop);
return NULL; if (exit) delete this;
pthread_exit(NULL);
} }
}; };