don't touch the key handle in NtOpenKey in failure cases
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c

Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c
--- trunk/reactos/ntoskrnl/cm/ntfunc.c	2005-12-10 16:38:04 UTC (rev 20038)
+++ trunk/reactos/ntoskrnl/cm/ntfunc.c	2005-12-10 17:00:54 UTC (rev 20039)
@@ -1256,7 +1256,7 @@
   UNICODE_STRING RemainingPath;
   KPROCESSOR_MODE PreviousMode;
   PVOID Object = NULL;
-  HANDLE hKey;
+  HANDLE hKey = NULL;
   NTSTATUS Status = STATUS_SUCCESS;
   UNICODE_STRING ObjectName;
   OBJECT_CREATE_INFORMATION ObjectCreateInfo;
@@ -1333,8 +1333,7 @@
   if (!NT_SUCCESS(Status))
     {
       DPRINT("CmpFindObject() returned 0x%08lx\n", Status);
-      Status = STATUS_INVALID_HANDLE; /* Because CmpFindObject returns STATUS_UNSUCCESSFUL */
-      hKey = *KeyHandle; /* Preserve hkResult value */
+      Status = STATUS_INVALID_HANDLE; /* Because ObFindObject returns STATUS_UNSUCCESSFUL */
       goto openkey_cleanup;
     }
 
@@ -1346,7 +1345,6 @@
     {
       RtlFreeUnicodeString(&RemainingPath);
       Status = STATUS_OBJECT_NAME_NOT_FOUND;
-      hKey = NULL;
       goto openkey_cleanup;
     }
 
@@ -1356,7 +1354,6 @@
   if (((PKEY_OBJECT)Object)->Flags & KO_MARKED_FOR_DELETE)
     {
       Status = STATUS_UNSUCCESSFUL;
-      hKey = NULL;
       goto openkey_cleanup;
     }
 
@@ -1365,9 +1362,6 @@
 			   ObjectCreateInfo.Attributes,
 			   &hKey);
 
-  if (!NT_SUCCESS(Status))
-     hKey = NULL;
-
 openkey_cleanup:
 
   ObpReleaseCapturedAttributes(&ObjectCreateInfo);
@@ -1381,15 +1375,18 @@
       ObDereferenceObject(Object);
     }
 
-  _SEH_TRY
+  if (NT_SUCCESS(Status))
   {
-    *KeyHandle = hKey;
+    _SEH_TRY
+    {
+      *KeyHandle = hKey;
+    }
+    _SEH_HANDLE
+    {
+      Status = _SEH_GetExceptionCode();
+    }
+    _SEH_END;
   }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
 
   return Status;
 }