[ros-diffs] [cgutman] 46285: [NTOSKRNL] - Fix a memory leak of the allocated IO_STATUS_BLOCK - Don't free unallocated memory - Send the IRP with the correct MajorFunction - Use IoBuildAsynchronousFsdRequest instead of IoBuildSynchronousFsdRequest (fixes potiential null pointer access when attempting to set the wait event which is NULL) - Set the correct stack parameters for the IRPs

cgutman at svn.reactos.org cgutman at svn.reactos.org
Sat Mar 20 17:48:01 CET 2010


Author: cgutman
Date: Sat Mar 20 17:48:00 2010
New Revision: 46285

URL: http://svn.reactos.org/svn/reactos?rev=46285&view=rev
Log:
[NTOSKRNL]
 - Fix a memory leak of the allocated IO_STATUS_BLOCK
 - Don't free unallocated memory
 - Send the IRP with the correct MajorFunction
 - Use IoBuildAsynchronousFsdRequest instead of IoBuildSynchronousFsdRequest (fixes potiential null pointer access when attempting to set the wait event which is NULL)
 - Set the correct stack parameters for the IRPs

Modified:
    trunk/reactos/ntoskrnl/po/power.c

Modified: trunk/reactos/ntoskrnl/po/power.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/po/power.c?rev=46285&r1=46284&r2=46285&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/po/power.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/po/power.c [iso-8859-1] Sat Mar 20 17:48:00 2010
@@ -47,9 +47,10 @@
                                         RequestPowerItem->PowerState,
                                         RequestPowerItem->Context,
                                         &Irp->IoStatus);
-  
-    ExFreePool(&Irp->IoStatus);
+
     ExFreePool(Context);
+
+    IoFreeIrp(Irp);
 
     return STATUS_SUCCESS;
 }
@@ -358,7 +359,6 @@
     PDEVICE_OBJECT TopDeviceObject;
     PIO_STACK_LOCATION Stack;
     PIRP Irp;
-    PIO_STATUS_BLOCK IoStatusBlock;
     PREQUEST_POWER_ITEM RequestPowerItem;
     NTSTATUS Status;
   
@@ -370,27 +370,19 @@
     RequestPowerItem = ExAllocatePool(NonPagedPool, sizeof(REQUEST_POWER_ITEM));
     if (!RequestPowerItem)
         return STATUS_INSUFFICIENT_RESOURCES;
-    IoStatusBlock = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
-    if (!IoStatusBlock)
-    {
-        ExFreePool(RequestPowerItem);
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
   
     /* Always call the top of the device stack */
     TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
   
-    Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
-                                       TopDeviceObject,
-                                       NULL,
-                                       0,
-                                       NULL,
-                                       NULL,
-                                       IoStatusBlock);
+    Irp = IoBuildAsynchronousFsdRequest(IRP_MJ_POWER,
+                                        TopDeviceObject,
+                                        NULL,
+                                        0,
+                                        NULL,
+                                        NULL);
     if (!Irp)
     {
         ExFreePool(RequestPowerItem);
-        ExFreePool(IoStatusBlock);
         return STATUS_INSUFFICIENT_RESOURCES;
     }
   
@@ -404,7 +396,10 @@
     if (MinorFunction == IRP_MN_WAIT_WAKE)
         Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
     else
-        Stack->Parameters.WaitWake.PowerState = PowerState.DeviceState;
+    {
+        Stack->Parameters.Power.Type = DevicePowerState;
+        Stack->Parameters.Power.State = PowerState.DeviceState;
+    }
   
     RequestPowerItem->CompletionRoutine = CompletionFunction;
     RequestPowerItem->PowerState = PowerState;




More information about the Ros-diffs mailing list