Author: tkreuzer Date: Thu Sep 18 10:39:54 2014 New Revision: 64186
URL: http://svn.reactos.org/svn/reactos?rev=64186&view=rev Log: [RTL] - 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
Modified: trunk/reactos/lib/rtl/registry.c
Modified: trunk/reactos/lib/rtl/registry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/registry.c?rev=6418... ============================================================================== --- trunk/reactos/lib/rtl/registry.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/registry.c [iso-8859-1] Thu Sep 18 10:39:54 2014 @@ -551,6 +551,20 @@ 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 @@ &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 @@ &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 @@ 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 @@ 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 @@ 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 @@ }
/* 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 */