Author: tfaber
Date: Sat May 11 12:17:36 2013
New Revision: 58993

URL: http://svn.reactos.org/svn/reactos?rev=58993&view=rev
Log:
[KBDHID][MOUHID]
- Free device resources

Modified:
    trunk/reactos/drivers/hid/kbdhid/kbdhid.c
    trunk/reactos/drivers/hid/mouhid/mouhid.c

Modified: trunk/reactos/drivers/hid/kbdhid/kbdhid.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/hid/kbdhid/kbdhid.c?rev=58993&r1=58992&r2=58993&view=diff
==============================================================================
--- trunk/reactos/drivers/hid/kbdhid/kbdhid.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/hid/kbdhid/kbdhid.c   [iso-8859-1] Sat May 11 
12:17:36 2013
@@ -773,6 +773,47 @@
 
 NTSTATUS
 NTAPI
+KbdHid_FreeResources(
+    IN PDEVICE_OBJECT DeviceObject)
+{
+    PKBDHID_DEVICE_EXTENSION DeviceExtension;
+
+    /* get device extension */
+    DeviceExtension = DeviceObject->DeviceExtension;
+
+    /* free resources */
+    if (DeviceExtension->PreparsedData)
+    {
+        ExFreePool(DeviceExtension->PreparsedData);
+        DeviceExtension->PreparsedData = NULL;
+    }
+
+    if (DeviceExtension->CurrentUsageList)
+    {
+        ExFreePool(DeviceExtension->CurrentUsageList);
+        DeviceExtension->CurrentUsageList = NULL;
+        DeviceExtension->PreviousUsageList = NULL;
+        DeviceExtension->MakeUsageList = NULL;
+        DeviceExtension->BreakUsageList = NULL;
+    }
+
+    if (DeviceExtension->ReportMDL)
+    {
+        IoFreeMdl(DeviceExtension->ReportMDL);
+        DeviceExtension->ReportMDL = NULL;
+    }
+
+    if (DeviceExtension->Report)
+    {
+        ExFreePool(DeviceExtension->Report);
+        DeviceExtension->Report = NULL;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NTAPI
 KbdHid_Flush(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp)
@@ -818,6 +859,10 @@
     switch (IoStack->MinorFunction)
     {
     case IRP_MN_STOP_DEVICE:
+    case IRP_MN_SURPRISE_REMOVAL:
+        /* free resources */
+        KbdHid_FreeResources(DeviceObject);
+        /* fall through */
     case IRP_MN_CANCEL_REMOVE_DEVICE:
     case IRP_MN_QUERY_STOP_DEVICE:
     case IRP_MN_CANCEL_STOP_DEVICE:
@@ -836,6 +881,9 @@
 
         /* cancel irp */
         IoCancelIrp(DeviceExtension->Irp);
+
+        /* free resources */
+        KbdHid_FreeResources(DeviceObject);
 
         /* indicate success */
         Irp->IoStatus.Status = STATUS_SUCCESS;

Modified: trunk/reactos/drivers/hid/mouhid/mouhid.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/hid/mouhid/mouhid.c?rev=58993&r1=58992&r2=58993&view=diff
==============================================================================
--- trunk/reactos/drivers/hid/mouhid/mouhid.c   [iso-8859-1] (original)
+++ trunk/reactos/drivers/hid/mouhid/mouhid.c   [iso-8859-1] Sat May 11 
12:17:36 2013
@@ -904,6 +904,47 @@
 
 NTSTATUS
 NTAPI
+MouHid_FreeResources(
+    IN PDEVICE_OBJECT DeviceObject)
+{
+    PMOUHID_DEVICE_EXTENSION DeviceExtension;
+
+    /* get device extension */
+    DeviceExtension = DeviceObject->DeviceExtension;
+
+    /* free resources */
+    if (DeviceExtension->PreparsedData)
+    {
+        ExFreePool(DeviceExtension->PreparsedData);
+        DeviceExtension->PreparsedData = NULL;
+    }
+
+    if (DeviceExtension->CurrentUsageList)
+    {
+        ExFreePool(DeviceExtension->CurrentUsageList);
+        DeviceExtension->CurrentUsageList = NULL;
+        DeviceExtension->PreviousUsageList = NULL;
+        DeviceExtension->MakeUsageList = NULL;
+        DeviceExtension->BreakUsageList = NULL;
+    }
+
+    if (DeviceExtension->ReportMDL)
+    {
+        IoFreeMdl(DeviceExtension->ReportMDL);
+        DeviceExtension->ReportMDL = NULL;
+    }
+
+    if (DeviceExtension->Report)
+    {
+        ExFreePool(DeviceExtension->Report);
+        DeviceExtension->Report = NULL;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NTAPI
 MouHid_Flush(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp)
@@ -949,6 +990,9 @@
     switch (IoStack->MinorFunction)
     {
     case IRP_MN_STOP_DEVICE:
+    case IRP_MN_SURPRISE_REMOVAL:
+        /* free resources */
+        MouHid_FreeResources(DeviceObject);
     case IRP_MN_CANCEL_REMOVE_DEVICE:
     case IRP_MN_QUERY_STOP_DEVICE:
     case IRP_MN_CANCEL_STOP_DEVICE:
@@ -970,6 +1014,9 @@
 
         /* cancel irp */
         IoCancelIrp(DeviceExtension->Irp);
+
+        /* free resources */
+        MouHid_FreeResources(DeviceObject);
 
         /* indicate success */
         Irp->IoStatus.Status = STATUS_SUCCESS;


Reply via email to