Decrease block protected by the mutex. Closes CID #1258573
authorAlan T. DeKok <aland@freeradius.org>
Mon, 15 Dec 2014 20:38:00 +0000 (15:38 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 15 Dec 2014 20:38:39 +0000 (15:38 -0500)
src/main/threads.c

index 7fb4cb5..59e9935 100644 (file)
@@ -1258,7 +1258,6 @@ pid_t rad_fork(void)
        /*
         *      Fork & save the PID for later reaping.
         */
-       pthread_mutex_lock(&thread_pool.wait_mutex);
        child_pid = fork();
        if (child_pid > 0) {
                int rcode;
@@ -1269,7 +1268,9 @@ pid_t rad_fork(void)
 
                tf->pid = child_pid;
 
+               pthread_mutex_lock(&thread_pool.wait_mutex);
                rcode = fr_hash_table_insert(thread_pool.waiters, tf);
+               pthread_mutex_unlock(&thread_pool.wait_mutex);
 
                if (!rcode) {
                        ERROR("Failed to store PID, creating what will be a zombie process %d",
@@ -1277,12 +1278,6 @@ pid_t rad_fork(void)
                        free(tf);
                }
        }
-       /*
-        *      Do not unlock in child process
-        */
-       if(child_pid != 0 ) {
-               pthread_mutex_unlock(&thread_pool.wait_mutex);
-       }
 
        /*
         *      Return whatever we were told.