[RTL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 18 Sep 2014 10:39:54 +0000 (10:39 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 18 Sep 2014 10:39:54 +0000 (10:39 +0000)
- Implement RtlpCloseRegistryHandle helper, which closes a registry key, if RTL_REGISTRY_HANDLE was not passed as RelativeTo
- Use RtlpCloseRegistryHandle whereever required, fixing some cases, where we unconditionally closed the handle

svn path=/trunk/; revision=64186

reactos/lib/rtl/registry.c

index 2645484..ed158e8 100644 (file)
@@ -551,6 +551,20 @@ RtlpGetRegistryHandle(IN ULONG RelativeTo,
     return Status;
 }
 
+FORCEINLINE
+VOID
+RtlpCloseRegistryHandle(
+    _In_ ULONG RelativeTo,
+    _In_ HANDLE KeyHandle)
+{
+    /* Did the caller pass a key handle? */
+    if (!(RelativeTo & RTL_REGISTRY_HANDLE))
+    {
+        /* We opened the key in RtlpGetRegistryHandle, so close it now */
+        ZwClose(KeyHandle);
+    }
+}
+
 /* PUBLIC FUNCTIONS **********************************************************/
 
 /*
@@ -572,7 +586,7 @@ RtlCheckRegistryKey(IN ULONG RelativeTo,
                                    &KeyHandle);
     if (!NT_SUCCESS(Status)) return Status;
 
-    /* All went well, close the handle and return success */
+    /* Close the handle even for RTL_REGISTRY_HANDLE */
     ZwClose(KeyHandle);
     return STATUS_SUCCESS;
 }
@@ -596,8 +610,8 @@ RtlCreateRegistryKey(IN ULONG RelativeTo,
                                    &KeyHandle);
     if (!NT_SUCCESS(Status)) return Status;
 
-    /* All went well, close the handle and return success */
-    ZwClose(KeyHandle);
+    /* All went well, close the handle and return status */
+    RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
     return STATUS_SUCCESS;
 }
 
@@ -626,8 +640,8 @@ RtlDeleteRegistryValue(IN ULONG RelativeTo,
     RtlInitUnicodeString(&Name, ValueName);
     Status = ZwDeleteValueKey(KeyHandle, &Name);
 
-    /* All went well, close the handle and return status */
-    ZwClose(KeyHandle);
+    /* Close the handle and return status */
+    RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
     return Status;
 }
 
@@ -664,13 +678,8 @@ RtlWriteRegistryValue(IN ULONG RelativeTo,
                            ValueData,
                            ValueLength);
 
-    /* Did the caller pass a key handle? */
-    if (!(RelativeTo & RTL_REGISTRY_HANDLE))
-    {
-        /* We opened the key in RtlpGetRegistryHandle, so close it now */
-        ZwClose(KeyHandle);
-    }
-
+    /* Close the handle and return status */
+    RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
     return Status;
 }
 
@@ -1017,7 +1026,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
     if (!KeyValueInfo)
     {
         /* Close the handle if we have one and fail */
-        if (!(RelativeTo & RTL_REGISTRY_HANDLE)) ZwClose(KeyHandle);
+        RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
         return Status;
     }
 
@@ -1318,7 +1327,7 @@ ProcessValues:
     }
 
     /* Check if we need to close our handle */
-    if ((KeyHandle) && !(RelativeTo & RTL_REGISTRY_HANDLE)) ZwClose(KeyHandle);
+    if (KeyHandle) RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
     if ((CurrentKey) && (CurrentKey != KeyHandle)) ZwClose(CurrentKey);
 
     /* Free our buffer and return status */