X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Flib%2Frtl%2Fregistry.c;h=ed158e801dd9fd60cff03e30fcea9becf467cb21;hp=26454849440bf22a4864435a10c2382470caa3e3;hb=bcaee07f8926fe0811869e7a416ef5d99992ec5e;hpb=7697e22142268b13d64554f094ada08fe06c9426 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 */