Index: reactos/ntoskrnl/io/iomgr/device.c =================================================================== --- reactos/ntoskrnl/io/iomgr/device.c (revision 35875) +++ reactos/ntoskrnl/io/iomgr/device.c (working copy) @@ -910,6 +910,9 @@ /* Set the pending delete flag */ IoGetDevObjExtension(DeviceObject)->ExtensionFlags |= DOE_DELETE_PENDING; + /* Dereference the DriverObject (refd inside IoCreateDevice funtion) */ + ObDereferenceObject(DeviceObject->DriverObject); + /* Check if the device object can be unloaded */ if (!DeviceObject->ReferenceCount) IopUnloadDevice(DeviceObject); } Index: reactos/ntoskrnl/io/iomgr/driver.c =================================================================== --- reactos/ntoskrnl/io/iomgr/driver.c (revision 35875) +++ reactos/ntoskrnl/io/iomgr/driver.c (working copy) @@ -1098,10 +1098,18 @@ } /* Unload the driver */ + /* Dereference one time (refd inside this function) */ ObDereferenceObject(DriverObject); - ObDereferenceObject(DriverObject); + + /* Unload the image */ MmUnloadSystemImage(DriverObject->DriverSection); + /* Make the object temporary, so it can be removed from Object directory when RefCount = 0 */ + ObMakeTemporaryObject(DriverObject); + + /* Derefernce once more (refd inside IopCreateDriver function) */ + ObDereferenceObject(DriverObject); + return STATUS_SUCCESS; } else