]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD: Fixed a race condition triggered by invoking pthread_detach() with an argument...
authorBart Van Assche <bvanassche@acm.org>
Tue, 8 Mar 2011 18:34:44 +0000 (18:34 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 8 Mar 2011 18:34:44 +0000 (18:34 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11612

drd/drd_pthread_intercepts.c

index aae0582807321aca2aea08c8490d22c812ef626f..45a464c3025a6d70408255335b4bd14985523c53 100644 (file)
@@ -269,7 +269,6 @@ static void* DRD_(thread_wrapper)(void* arg)
 
    arg_ptr = (DrdPosixThreadArgs*)arg;
    arg_copy = *arg_ptr;
-   arg_ptr->wrapper_started = 1;
 
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
                               pthread_self(), 0, 0, 0, 0);
@@ -277,6 +276,13 @@ static void* DRD_(thread_wrapper)(void* arg)
    DRD_(set_joinable)(pthread_self(),
                       arg_copy.detachstate == PTHREAD_CREATE_JOINABLE);
 
+   /*
+    * Only set 'wrapper_started' after VG_USERREQ__SET_PTHREADID and
+    * DRD_(set_joinable)() have been invoked to avoid a race with
+    * a pthread_detach() invocation for this thread from another thread.
+    */
+   arg_ptr->wrapper_started = 1;
+
    return (arg_copy.start)(arg_copy.arg);
 }