[AD] Resource leak (threads)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


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






Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/