diff --git a/reactos/ntoskrnl/lpc/close.c b/reactos/ntoskrnl/lpc/close.c index a8fb1ad1fc9..f94e320e3d6 100644 --- a/reactos/ntoskrnl/lpc/close.c +++ b/reactos/ntoskrnl/lpc/close.c @@ -432,6 +432,15 @@ LpcpDeletePort(IN PVOID ObjectBody) /* Dereference the object unless it's the same port */ if (ConnectionPort != Port) ObDereferenceObject(ConnectionPort); + + /* Check if this is a connection port with a server process */ + if (((Port->Flags & LPCP_PORT_TYPE_MASK) == LPCP_CONNECTION_PORT) && + (ConnectionPort->ServerProcess)) + { + /* Dereference the server process */ + ObDereferenceObject(ConnectionPort->ServerProcess); + ConnectionPort->ServerProcess = NULL; + } } else { @@ -439,15 +448,6 @@ LpcpDeletePort(IN PVOID ObjectBody) KeReleaseGuardedMutex(&LpcpLock); } - /* Check if this is a connection port with a server process */ - if (((Port->Flags & LPCP_PORT_TYPE_MASK) == LPCP_CONNECTION_PORT) && - (ConnectionPort->ServerProcess)) - { - /* Dereference the server process */ - ObDereferenceObject(ConnectionPort->ServerProcess); - ConnectionPort->ServerProcess = NULL; - } - /* Free client security */ LpcpFreePortClientSecurity(Port); LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p deleted\n", Port);