From bcaee07f8926fe0811869e7a416ef5d99992ec5e Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 18 Sep 2014 10:39:54 +0000 Subject: [PATCH] [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 svn path=/trunk/; revision=64186 --- reactos/lib/rtl/registry.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/reactos/lib/rtl/registry.c b/reactos/lib/rtl/registry.c index 26454849440..ed158e801dd 100644 --- a/reactos/lib/rtl/registry.c +++ b/reactos/lib/rtl/registry.c @@ -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 */