diff --git a/2.x/trunk/ProcessHacker/include/ref.h b/2.x/trunk/ProcessHacker/include/ref.h index 08c52ba6d..8d748cf4d 100644 --- a/2.x/trunk/ProcessHacker/include/ref.h +++ b/2.x/trunk/ProcessHacker/include/ref.h @@ -39,7 +39,7 @@ * an object of the type is being freed. * * \param Object A pointer to the object being freed. - * \param Flags The flags specified when the object was created. + * \param Flags Reserved. */ typedef VOID (NTAPI *PPH_TYPE_DELETE_PROCEDURE)( __in PVOID Object, diff --git a/2.x/trunk/ProcessHacker/include/refp.h b/2.x/trunk/ProcessHacker/include/refp.h index 5a9219d67..22b613d08 100644 --- a/2.x/trunk/ProcessHacker/include/refp.h +++ b/2.x/trunk/ProcessHacker/include/refp.h @@ -62,7 +62,7 @@ typedef struct _PH_OBJECT_HEADER { /** The reference count of the object. */ LONG RefCount; - /** The flags that were used to create the object. */ + /** Reserved. */ ULONG Flags; union { diff --git a/2.x/trunk/ProcessHacker/ref.c b/2.x/trunk/ProcessHacker/ref.c index 55bab41bd..bfafd6b1c 100644 --- a/2.x/trunk/ProcessHacker/ref.c +++ b/2.x/trunk/ProcessHacker/ref.c @@ -112,40 +112,45 @@ __mayRaise NTSTATUS PhCreateObject( __in_opt LONG AdditionalReferences ) { + NTSTATUS status = STATUS_SUCCESS; PPH_OBJECT_HEADER objectHeader; - + /* Check the flags. */ if ((Flags & PHOBJ_VALID_FLAGS) != Flags) /* Valid flag mask */ - return STATUS_INVALID_PARAMETER_3; + { + status = STATUS_INVALID_PARAMETER_3; + } /* The object type is only optional if the fundamental object type * hasn't been created. */ - if (!ObjectType && PhObjectTypeObject) - return STATUS_INVALID_PARAMETER_4; + else if (!ObjectType && PhObjectTypeObject) + { + status = STATUS_INVALID_PARAMETER_4; + } /* Make sure the additional reference count isn't negative. */ - if (AdditionalReferences < 0) - return STATUS_INVALID_PARAMETER_5; - + else if (AdditionalReferences < 0) + { + status = STATUS_INVALID_PARAMETER_5; + } + /* Allocate storage for the object. Note that this includes * the object header followed by the object body. */ objectHeader = PhpAllocateObject(ObjectSize); - + if (!objectHeader) - { - if (Flags & PHOBJ_RAISE_ON_FAIL) - PhRaiseStatus(STATUS_INSUFFICIENT_RESOURCES); - else - return STATUS_INSUFFICIENT_RESOURCES; - } - + status = STATUS_INSUFFICIENT_RESOURCES; + + if (!NT_SUCCESS(status) && (Flags & PHOBJ_RAISE_ON_FAIL)) + PhRaiseStatus(status); + /* Object type statistics. */ if (ObjectType) { _InterlockedIncrement((PLONG)&ObjectType->NumberOfObjects); } - + /* Initialize the object header. */ objectHeader->RefCount = 1 + AdditionalReferences; - objectHeader->Flags = Flags; + objectHeader->Flags = 0; objectHeader->Size = ObjectSize; objectHeader->Type = ObjectType; @@ -175,11 +180,11 @@ __mayRaise NTSTATUS PhCreateObject( ); } #endif - + /* Pass a pointer to the object body back to the caller. */ *Object = PhObjectHeaderToObject(objectHeader); - - return STATUS_SUCCESS; + + return status; } /** @@ -533,7 +538,7 @@ VOID PhpFreeObject( { ObjectHeader->Type->DeleteProcedure( PhObjectHeaderToObject(ObjectHeader), - ObjectHeader->Flags + 0 ); }