diff --git a/reactos/ntoskrnl/cm/ntfunc.c b/reactos/ntoskrnl/cm/ntfunc.c index 2df1d94414e..16708499f2e 100644 --- a/reactos/ntoskrnl/cm/ntfunc.c +++ b/reactos/ntoskrnl/cm/ntfunc.c @@ -322,24 +322,6 @@ NtCreateKey(OUT PHANDLE KeyHandle, goto Cleanup; } - Status = ObInsertObject((PVOID)KeyObject, - NULL, - DesiredAccess, - 0, - NULL, - &hKey); - if (!NT_SUCCESS(Status)) - { - ObDereferenceObject(KeyObject); - DPRINT1("ObInsertObject() failed!\n"); - - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - goto Cleanup; - } - KeyObject->ParentKey = Object; KeyObject->RegistryHive = KeyObject->ParentKey->RegistryHive; KeyObject->Flags = 0; @@ -398,6 +380,28 @@ NtCreateKey(OUT PHANDLE KeyHandle, VERIFY_KEY_OBJECT(KeyObject); + Status = CmpCreateHandle(KeyObject, + DesiredAccess, + ObjectCreateInfo.Attributes, + &hKey); + + /* Free the create information */ + ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(KeyObject)->ObjectCreateInfo); + OBJECT_TO_OBJECT_HEADER(KeyObject)->ObjectCreateInfo = NULL; + + if (!NT_SUCCESS(Status)) + { + DPRINT1("ObInsertObject() failed!\n"); + + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + goto Cleanup; + } + + /* Add the keep-alive reference */ + ObReferenceObject(KeyObject); /* Release hive lock */ ExReleaseResourceLite(&CmpRegistryLock); KeLeaveCriticalRegion(); diff --git a/reactos/ntoskrnl/cm/registry.c b/reactos/ntoskrnl/cm/registry.c index e5d0ac796a2..9cfd88efa08 100644 --- a/reactos/ntoskrnl/cm/registry.c +++ b/reactos/ntoskrnl/cm/registry.c @@ -281,20 +281,6 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, return Status; } -#if 0 - DPRINT("Inserting Key into Object Tree\n"); - Status = ObInsertObject((PVOID)NewKey, - NULL, - KEY_ALL_ACCESS, - 0, - NULL, - NULL); - DPRINT("Status %x\n", Status); -#else - /* Free the create information */ - ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo); - OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo = NULL; -#endif NewKey->Flags = 0; NewKey->SubKeyCounts = 0; NewKey->SubKeys = NULL; @@ -333,6 +319,10 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, return STATUS_INSUFFICIENT_RESOURCES; } + /* Free the create information */ + ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo); + OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo = NULL; + /* FN1 */ ObReferenceObject (NewKey);