summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-04 22:13:47 +0000
committerrubidium <rubidium@openttd.org>2008-05-04 22:13:47 +0000
commit7a85e26268fe1b931753194f207132efcd9325fe (patch)
tree4857db07ae4e064b111ce01949e88748512f3da4 /src
parent297f99e100bcede36d54b8f833756c73d70fd4a0 (diff)
downloadopenttd-7a85e26268fe1b931753194f207132efcd9325fe.tar.xz
(svn r12945) -Fix: (small) memory leak when joining/exiting threads.
Diffstat (limited to 'src')
-rw-r--r--src/thread_pthread.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/thread_pthread.cpp b/src/thread_pthread.cpp
index 4645e4027..07d5e39b2 100644
--- a/src/thread_pthread.cpp
+++ b/src/thread_pthread.cpp
@@ -104,6 +104,8 @@ public:
pthread_join(m_thr, &ret);
m_thr = 0;
+ delete this;
+
return ret;
}
@@ -136,16 +138,22 @@ private:
/* 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);
}
};