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 **********************************************************/
/*
&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;
}
&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;
}
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;
}
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;
}
if (!KeyValueInfo)
{
/* Close the handle if we have one and fail */
- if (!(RelativeTo & RTL_REGISTRY_HANDLE)) ZwClose(KeyHandle);
+ RtlpCloseRegistryHandle(RelativeTo, KeyHandle);
return Status;
}
}
/* 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 */