Removed most calls to xmalloc/xrealloc.

diff --git a/scheduler/client.c b/scheduler/client.c
index 6767416..f148f53 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -30,7 +30,6 @@
 #include "server.h"
 #include "winerror.h"
 #include "options.h"
-#include "xmalloc.h"
 
 /* Some versions of glibc don't define this */
 #ifndef SCM_RIGHTS
@@ -305,7 +304,8 @@
             execl( BINDIR "/wineserver", "wineserver", NULL );
             if (oldcwd) chdir( oldcwd );
             /* now try the dir we were launched from */
-            path = xmalloc( strlen(argv0) + 20 );
+            if (!(path = malloc( strlen(argv0) + 20 )))
+                fatal_error( "out of memory\n" );
             if ((p = strrchr( strcpy( path, argv0 ), '/' )))
             {
                 strcpy( p, "/wineserver" );
@@ -396,7 +396,7 @@
     /* retrieve the current directory */
     for (size = 512; ; size *= 2)
     {
-        oldcwd = xmalloc( size );
+        if (!(oldcwd = malloc( size ))) break;
         if (getcwd( oldcwd, size )) break;
         free( oldcwd );
         if (errno == ERANGE) continue;
@@ -407,7 +407,8 @@
     /* get the server directory name */
     if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" );
     configdir = PROFILE_GetConfigDir();
-    serverdir = xmalloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 );
+    serverdir = malloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 );
+    if (!serverdir) fatal_error( "out of memory\n" );
     strcpy( serverdir, configdir );
     strcat( serverdir, SERVERDIR );
     strcat( serverdir, hostname );
diff --git a/scheduler/critsection.c b/scheduler/critsection.c
index c5560fa..3c8c587 100644
--- a/scheduler/critsection.c
+++ b/scheduler/critsection.c
@@ -115,20 +115,21 @@
  */
 BOOL WINAPI TryEnterCriticalSection( CRITICAL_SECTION *crit )
 {
-    if (InterlockedIncrement( &crit->LockCount ))
+    BOOL ret = FALSE;
+    if (InterlockedCompareExchange( (PVOID *)&crit->LockCount,
+                                    (PVOID)0L, (PVOID)-1L ) == (PVOID)-1L)
     {
-        if (crit->OwningThread == GetCurrentThreadId())
-        {
-            crit->RecursionCount++;
-            return TRUE;
-        }
-        /* FIXME: this doesn't work */
-        InterlockedDecrement( &crit->LockCount );
-        return FALSE;
+        crit->OwningThread   = GetCurrentThreadId();
+        crit->RecursionCount = 1;
+        ret = TRUE;
     }
-    crit->OwningThread   = GetCurrentThreadId();
-    crit->RecursionCount = 1;
-    return TRUE;
+    else if (crit->OwningThread == GetCurrentThreadId())
+    {
+	InterlockedIncrement( &crit->LockCount );
+	crit->RecursionCount++;
+	ret = TRUE;
+    }
+    return ret;
 }