[ros-diffs] [ion] 23352: - Add another paramter to IopCleanupFailedIrp to free an optional buffer being specified to it. This way we don't leak some allocated buffers when IRP allocation fails. - Create inlined IopUnQueueIrpFromThread to match IopQueueIrpToThread.

ion at svn.reactos.org ion at svn.reactos.org
Sat Jul 29 18:56:26 CEST 2006


Author: ion
Date: Sat Jul 29 20:56:26 2006
New Revision: 23352

URL: http://svn.reactos.org/svn/reactos?rev=23352&view=rev
Log:
- Add another paramter to IopCleanupFailedIrp to free an optional buffer being specified to it. This way we don't leak some allocated buffers when IRP allocation fails.
- Create inlined IopUnQueueIrpFromThread to match IopQueueIrpToThread.

Modified:
    trunk/reactos/ntoskrnl/KrnlFun.c
    trunk/reactos/ntoskrnl/include/internal/io.h
    trunk/reactos/ntoskrnl/include/internal/io_x.h
    trunk/reactos/ntoskrnl/io/iomgr/file.c
    trunk/reactos/ntoskrnl/io/iomgr/iofunc.c
    trunk/reactos/ntoskrnl/io/iomgr/irp.c

Modified: trunk/reactos/ntoskrnl/KrnlFun.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/KrnlFun.c?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/KrnlFun.c (original)
+++ trunk/reactos/ntoskrnl/KrnlFun.c Sat Jul 29 20:56:26 2006
@@ -10,7 +10,6 @@
 //
 // Io:
 //  - See why queueing IRPs and cancelling them causes crashes.
-//  - Add another parameter to IopCleanupFailedIrp.
 //  - Add Access Checks in IopParseDevice.
 //  - Add validation checks in IoCreateFile.
 //  - Add probe/alignment checks for Query/Set routines.

Modified: trunk/reactos/ntoskrnl/include/internal/io.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/io.h?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/io.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/io.h Sat Jul 29 20:56:26 2006
@@ -666,7 +666,8 @@
 NTAPI
 IopCleanupFailedIrp(
     IN PFILE_OBJECT FileObject,
-    IN PKEVENT EventObject
+    IN PKEVENT EventObject,
+    IN PVOID Buffer OPTIONAL
 );
 
 VOID

Modified: trunk/reactos/ntoskrnl/include/internal/io_x.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/io_x.h?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/io_x.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/io_x.h Sat Jul 29 20:56:26 2006
@@ -41,6 +41,15 @@
 
     /* Lower irql */
     KeLowerIrql(OldIrql);
+}
+
+VOID
+FORCEINLINE
+IopUnQueueIrpFromThread(IN PIRP Irp)
+{
+    /* Remove it from the list and reset it */
+    RemoveEntryList(&Irp->ThreadListEntry);
+    InitializeListHead(&Irp->ThreadListEntry);
 }
 
 VOID

Modified: trunk/reactos/ntoskrnl/io/iomgr/file.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/file.c?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/file.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/file.c Sat Jul 29 20:56:26 2006
@@ -404,8 +404,7 @@
         FileObject->Event.Header.SignalState = 1;
 
         /* Now that we've signaled the events, de-associate the IRP */
-        //RemoveEntryList(&Irp->ThreadListEntry);
-        //InitializeListHead(&Irp->ThreadListEntry);
+        //IopUnQueueIrpFromThread(Irp);
 
         /* Check if the IRP had an input buffer */
         if ((Irp->Flags & IRP_BUFFERED_IO) &&
@@ -795,7 +794,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;

Modified: trunk/reactos/ntoskrnl/io/iomgr/iofunc.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/iofunc.c?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/iofunc.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/iofunc.c Sat Jul 29 20:56:26 2006
@@ -346,7 +346,7 @@
                                         FALSE,
                                         EventObject,
                                         IoStatusBlock);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
 
     /* Set some extra settings */
     Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID) NULL;
@@ -415,7 +415,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -673,7 +673,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -887,7 +887,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set up the IRP */
     Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
@@ -1017,7 +1017,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;
@@ -1165,7 +1165,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;
@@ -1366,7 +1366,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, EventHandle);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, EventHandle, AuxBuffer);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;
@@ -1587,7 +1587,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -1882,7 +1882,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -2129,7 +2129,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -2463,7 +2463,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;
@@ -2693,7 +2693,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
 
     /* Set the IRP */
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -2885,7 +2885,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;
@@ -3035,7 +3035,7 @@
 
     /* Allocate the IRP */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-    if (!Irp) return IopCleanupFailedIrp(FileObject, Event);
+    if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
 
     /* Set up the IRP */
     Irp->RequestorMode = PreviousMode;

Modified: trunk/reactos/ntoskrnl/io/iomgr/irp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/irp.c?rev=23352&r1=23351&r2=23352&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/irp.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/irp.c Sat Jul 29 20:56:26 2006
@@ -43,12 +43,16 @@
 NTSTATUS
 NTAPI
 IopCleanupFailedIrp(IN PFILE_OBJECT FileObject,
-                    IN PKEVENT EventObject)
+                    IN PKEVENT EventObject OPTIONAL,
+                    IN PVOID Buffer OPTIONAL)
 {
     PAGED_CODE();
 
     /* Dereference the event */
     if (EventObject) ObDereferenceObject(EventObject);
+
+    /* Free a buffer, if any */
+    if (Buffer) ExFreePool(Buffer);
 
     /* If this was a file opened for synch I/O, then unlock it */
     if (FileObject->Flags & FO_SYNCHRONOUS_IO) IopUnlockFileObject(FileObject);
@@ -348,8 +352,7 @@
         }
 
         /* Now that we've signaled the events, de-associate the IRP */
-        RemoveEntryList(&Irp->ThreadListEntry);
-        InitializeListHead(&Irp->ThreadListEntry);
+        IopUnQueueIrpFromThread(Irp);
 
         /* Now check if a User APC Routine was requested */
         if (Irp->Overlay.AsynchronousParameters.UserApcRoutine)
@@ -447,8 +450,7 @@
         }
 
         /* Now that we've signaled the events, de-associate the IRP */
-        RemoveEntryList(&Irp->ThreadListEntry);
-        InitializeListHead(&Irp->ThreadListEntry);
+        IopUnQueueIrpFromThread(Irp);
 
         /* Free the IRP as well */
         IoFreeIrp(Irp);




More information about the Ros-diffs mailing list