From b3ca862273f90035ac01e57f34c1a6ff7b46d1ed Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 5 Mar 2010 10:35:13 +0000 Subject: [PATCH] Fixed possible leak in sf::Thread implementation (thread handles could be lost if the same sf::Thread was launched again before finishing) git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1441 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/System/Unix/Thread.cpp | 6 ++++-- src/SFML/System/Win32/Thread.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SFML/System/Unix/Thread.cpp b/src/SFML/System/Unix/Thread.cpp index 3268f610e..da02399ac 100644 --- a/src/SFML/System/Unix/Thread.cpp +++ b/src/SFML/System/Unix/Thread.cpp @@ -61,8 +61,7 @@ myUserData(UserData) Thread::~Thread() { // Wait for the thread to finish before destroying the instance - if (myIsActive) - Wait(); + Wait(); } @@ -71,6 +70,9 @@ Thread::~Thread() //////////////////////////////////////////////////////////// void Thread::Launch() { + // Wait for the thread to finish, in case it was already running + Wait(); + // Create the thread myIsActive = true; int Error = pthread_create(&myThread, NULL, &Thread::ThreadFunc, this); diff --git a/src/SFML/System/Win32/Thread.cpp b/src/SFML/System/Win32/Thread.cpp index d2d1d8226..3252100fa 100644 --- a/src/SFML/System/Win32/Thread.cpp +++ b/src/SFML/System/Win32/Thread.cpp @@ -62,8 +62,7 @@ myUserData(UserData) Thread::~Thread() { // Wait for the thread to finish before destroying the instance - if (myHandle) - Wait(); + Wait(); } @@ -72,6 +71,9 @@ Thread::~Thread() //////////////////////////////////////////////////////////// void Thread::Launch() { + // Wait for the thread to finish, in case it was already running + Wait(); + // Create the thread myHandle = reinterpret_cast(_beginthreadex(NULL, 0, &Thread::ThreadFunc, this, 0, NULL));