adaint.c: Fix possible race condition on win32_wait().
authorPascal Obry <obry@adacore.com>
Fri, 22 Aug 2008 13:26:38 +0000 (15:26 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 22 Aug 2008 13:26:38 +0000 (15:26 +0200)
2008-08-22  Pascal Obry  <obry@adacore.com>

* adaint.c: Fix possible race condition on win32_wait().

From-SVN: r139466

gcc/ada/adaint.c

index 48abb3e..0971a02 100644 (file)
@@ -2266,6 +2266,7 @@ win32_wait (int *status)
   DWORD res;
   int k;
   Process_List *pl;
+  int hl_len;
 
   if (plist_length == 0)
     {
@@ -2273,12 +2274,14 @@ win32_wait (int *status)
       return -1;
     }
 
-  hl = (HANDLE *) xmalloc (sizeof (HANDLE) * plist_length);
-
   k = 0;
   plist_enter();
 
+  hl_len = plist_length;
+
   /* -------------------- critical section -------------------- */
+  hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len);
+
   pl = PLIST;
   while (pl)
     {
@@ -2289,7 +2292,7 @@ win32_wait (int *status)
 
   plist_leave();
 
-  res = WaitForMultipleObjects (plist_length, hl, FALSE, INFINITE);
+  res = WaitForMultipleObjects (hl_len, hl, FALSE, INFINITE);
   h = hl[res - WAIT_OBJECT_0];
   free (hl);