static NTSTATUS
-RegpDeleteTree(IN HKEY hKey,
- OUT PBOOLEAN KeysDeleted)
+RegpDeleteTree(IN HKEY hKey)
{
typedef struct
{
NTSTATUS Status = STATUS_SUCCESS;
NTSTATUS Status2 = STATUS_SUCCESS;
- *KeysDeleted = FALSE;
-
InitializeListHead(&delQueueHead);
ProcessHeap = RtlGetProcessHeap();
/* NOTE: do NOT close the handle anymore, it's invalid already! */
- if (!NT_SUCCESS(Status2) && NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status2))
{
- /* don't break, let's try to delete as many keys as possible */
- Status = Status2;
+ /* close the key handle so we don't leak handles for keys we were
+ unable to delete. But only do this for handles not supplied
+ by the caller! */
+
+ if (delKeys->KeyHandle != hKey)
+ {
+ NtClose(delKeys->KeyHandle);
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ /* don't break, let's try to delete as many keys as possible */
+ Status = Status2;
+ }
}
/* remove the entry from the list */
0,
delKeys);
} while (!IsListEmpty(&delQueueHead));
-
- *KeysDeleted = TRUE;
}
else
Status = STATUS_INSUFFICIENT_RESOURCES;
RegDeleteTreeW(IN HKEY hKey,
IN LPCWSTR lpSubKey OPTIONAL)
{
- BOOLEAN KeysDeleted;
HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
else
CurKey = KeyHandle;
- Status = RegpDeleteTree(CurKey,
- &KeysDeleted);
+ Status = RegpDeleteTree(CurKey);
- if (!KeysDeleted)
+ if (NT_SUCCESS(Status))
{
- /* only close handles of keys that weren't deleted! */
+ /* make sure we only close hKey (KeyHandle) when the caller specified a
+ subkey, because the handle would be invalid already! */
+ if (CurKey != KeyHandle)
+ {
+ CloseDefaultKey(KeyHandle);
+ }
+
+ return ERROR_SUCCESS;
+ }
+ else
+ {
+ /* make sure we close all handles we created! */
if (SubKeyHandle != NULL)
{
NtClose(SubKeyHandle);
Cleanup:
CloseDefaultKey(KeyHandle);
- }
-
- if (!NT_SUCCESS(Status))
- {
+
return RtlNtStatusToDosError(Status);
}
-
- return ERROR_SUCCESS;
}