From f0b8a1730e263400916ee4dca9dd3f0af8eab90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Sat, 15 Oct 2022 15:02:36 +0200 Subject: [PATCH] [VIDEOPRT] Correctly detach from device stack in case of failure --- win32ss/drivers/videoprt/videoprt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/win32ss/drivers/videoprt/videoprt.c b/win32ss/drivers/videoprt/videoprt.c index 337c3c84760..509c07288b3 100644 --- a/win32ss/drivers/videoprt/videoprt.c +++ b/win32ss/drivers/videoprt/videoprt.c @@ -244,9 +244,7 @@ IntVideoPortCreateAdapterDeviceObject( if (!NT_SUCCESS(Status)) { WARN_(VIDEOPRT, "IntCreateRegistryPath() call failed with status 0x%08x\n", Status); - IoDeleteDevice(*DeviceObject); - *DeviceObject = NULL; - return Status; + goto Failure; } if (PhysicalDeviceObject != NULL) @@ -314,9 +312,7 @@ IntVideoPortCreateAdapterDeviceObject( if (!NT_SUCCESS(Status)) { ERR_(VIDEOPRT, "IntCreateNewRegistryPath() failed with status 0x%08x\n", Status); - IoDeleteDevice(*DeviceObject); - *DeviceObject = NULL; - return Status; + goto Failure; } IntSetupDeviceSettingsKey(DeviceExtension); @@ -329,9 +325,7 @@ IntVideoPortCreateAdapterDeviceObject( if (!NT_SUCCESS(Status)) { ERR_(VIDEOPRT, "IntVideoPortAddDeviceMapLink() failed with status 0x%08x\n", Status); - IoDeleteDevice(*DeviceObject); - *DeviceObject = NULL; - return Status; + goto Failure; } if (DisplayNumber == 0) @@ -340,6 +334,13 @@ IntVideoPortCreateAdapterDeviceObject( } return STATUS_SUCCESS; + +Failure: + if (DeviceExtension->NextDeviceObject) + IoDetachDevice(DeviceExtension->NextDeviceObject); + IoDeleteDevice(*DeviceObject); + *DeviceObject = NULL; + return Status; }