[AD] Resource leak (threads) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: "'Allegro Development'" <alleg-developers@xxxxxxxxxx>
- Subject: [AD] Resource leak (threads)
- From: "Trent Gamblin" <trent@xxxxxxxxxx>
- Date: Sun, 6 Apr 2014 14:53:50 -0600
- Thread-index: Ac9R2cFRgXYkwZ91StKbB2nXbDQGjQ==
There is a pretty big resource leak with threading, at least on Windows. It
happens when you use al_create_thread (possibly al_run_detached_thread?) The
condition variable is never destroyed. On Windows that is 2 critical
sections and a semaphore leaked per thread started. I don't know if it
affects anything besides Windows, but this one liner fixes it for me:
diff --git a/src/threads.c b/src/threads.c
index e40f4b4..bcbb5a8 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -197,6 +197,7 @@ void al_join_thread(ALLEGRO_THREAD *thread, void
**ret_value)
thread->thread_state = THREAD_STATE_JOINING;
_al_cond_broadcast(&thread->cond);
_al_mutex_unlock(&thread->mutex);
+ _al_cond_destroy(&thread->cond);
_al_mutex_destroy(&thread->mutex);
_al_thread_join(&thread->thread);
thread->thread_state = THREAD_STATE_JOINED;
I ran my game through C++ Memory Validator quickly (1 minute) and it shows 9
or 10 critical sections leaked. After this patch there is still one that
looks leaked so I may have more changes after this.
Thanks,
Trent