[vlc-commits] android: fix detached threads leak

Rafaël Carré git at videolan.org
Wed Oct 17 13:13:29 CEST 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Wed Oct 17 13:12:50 2012 +0200| [ee02148b69a921bd28f77f0a9905bfea79083f78] | committer: Rafaël Carré

android: fix detached threads leak

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ee02148b69a921bd28f77f0a9905bfea79083f78
---

 src/android/thread.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/android/thread.c b/src/android/thread.c
index 2715388..7d15b2d 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -308,17 +308,25 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
 }
 
 /* pthread */
+static void clean_detached_thread(void *data)
+{
+    struct vlc_thread *thread = data;
+
+    /* release thread handle */
+    vlc_mutex_destroy(&thread->lock);
+    free(thread);
+}
 
 static void *detached_thread(void *data)
 {
     vlc_thread_t th = data;
 
     thread = th;
+
+    vlc_cleanup_push(clean_detached_thread, data);
     th->entry(th->data);
+    vlc_cleanup_run();
 
-    /* release thread handle */
-    vlc_mutex_destroy(&th->lock);
-    free(th);
     return NULL;
 }
 
@@ -454,7 +462,6 @@ void vlc_testcancel (void)
         return;
 
     vlc_sem_post(&thread->finished);
-#warning FIXME: memory leak for detached threads
     pthread_exit(NULL);
 }
 



More information about the vlc-commits mailing list