[USBSTOR] Do not leak fields of DeviceExtensions upon device removal
authorVictor Perevertkin <victor@perevertkin.ru>
Mon, 10 Jun 2019 22:31:44 +0000 (01:31 +0300)
committerVictor Perevertkin <victor@perevertkin.ru>
Tue, 11 Jun 2019 01:39:43 +0000 (04:39 +0300)
drivers/usb/usbstor/fdo.c
drivers/usb/usbstor/pdo.c

index 1c19495..6879b4e 100644 (file)
@@ -108,8 +108,27 @@ USBSTOR_FdoHandleRemoveDevice(
         }
     }
 
+    // Freeing everything in DeviceExtension
+    ASSERT(
+        DeviceExtension->DeviceDescriptor &&
+        DeviceExtension->ConfigurationDescriptor &&
+        DeviceExtension->InterfaceInformation &&
+        DeviceExtension->ResetDeviceWorkItem
+    );
+
+    ExFreePoolWithTag(DeviceExtension->DeviceDescriptor, USB_STOR_TAG);
+    ExFreePoolWithTag(DeviceExtension->ConfigurationDescriptor, USB_STOR_TAG);
+    ExFreePoolWithTag(DeviceExtension->InterfaceInformation, USB_STOR_TAG);
+    IoFreeWorkItem(DeviceExtension->ResetDeviceWorkItem);
+
+    if (DeviceExtension->SerialNumber)
+    {
+        ExFreePoolWithTag(DeviceExtension->SerialNumber, USB_STOR_TAG);
+    }
+
     // Send the IRP down the stack
     IoSkipCurrentIrpStackLocation(Irp);
+    Irp->IoStatus.Status = STATUS_SUCCESS;
     Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
 
     // Detach from the device stack
index b41cb93..9a84483 100644 (file)
@@ -575,6 +575,10 @@ USBSTOR_PdoHandlePnp(
                bDelete = FALSE;
            }
 
+           // clean up the device extension
+           ASSERT(DeviceExtension->InquiryData);
+           ExFreePoolWithTag(DeviceExtension->InquiryData, USB_STOR_TAG);
+
            Irp->IoStatus.Status = STATUS_SUCCESS;
            IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
@@ -658,7 +662,7 @@ USBSTOR_SyncCompletionRoutine(
 
 /*
 * @name USBSTOR_SendInternalCdb
-* 
+*
 * Issues an internal SCSI request to device.
 * The request is sent in a synchronous way.
 */