Index: libgomp/task.c
===================================================================
--- libgomp/task.c	(revision 181833)
+++ libgomp/task.c	(working copy)
@@ -116,12 +116,12 @@ GOMP_task (void (*fn) (void *), void *da
 	}
       else
 	fn (data);
-      if (task.children)
-	{
-	  gomp_mutex_lock (&team->task_lock);
-	  gomp_clear_parent (task.children);
-	  gomp_mutex_unlock (&team->task_lock);
-	}
+      if (team != NULL)
+	gomp_mutex_lock (&team->task_lock);
+      if (task.children != NULL)
+	gomp_clear_parent (task.children);
+      if (team != NULL)
+	gomp_mutex_unlock (&team->task_lock);
       gomp_end_task ();
     }
   else
@@ -290,8 +290,9 @@ GOMP_taskwait (void)
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
 
-  if (task == NULL || task->children == NULL)
+  if (task == NULL)
     return;
+
   gomp_mutex_lock (&team->task_lock);
   while (1)
     {
