Fix IopDeleteFile: Use IRP_SYNC_API flag, use local stack event, fix memory leak (Free completion context), dereference completion port, get the right deviceobject if FO_DIRECT_DEVICE_OPEN is set

svn path=/trunk/; revision=14920
This commit is contained in:
Alex Ionescu 2005-05-01 19:36:00 +00:00
parent 722d9a84e4
commit f7695b0f53

View file

@ -177,56 +177,71 @@ VOID
STDCALL STDCALL
IopDeleteFile(PVOID ObjectBody) IopDeleteFile(PVOID ObjectBody)
{ {
PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody; PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
PIRP Irp; PIRP Irp;
PIO_STACK_LOCATION StackPtr; PIO_STACK_LOCATION StackPtr;
NTSTATUS Status; NTSTATUS Status;
KEVENT Event;
PDEVICE_OBJECT DeviceObject;
IO_STATUS_BLOCK IoStatusBlock;
DPRINT("IopDeleteFile()\n"); DPRINT("IopDeleteFile()\n");
if (FileObject->DeviceObject) if (FileObject->DeviceObject)
{ {
#if 0 /* Check if this is a direct open or not */
//NOTE: Allmost certain that the latest changes to I/O Mgr makes this redundant (OriginalFileObject case) if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
{
ObReferenceObjectByPointer(ObjectBody, DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
STANDARD_RIGHTS_REQUIRED, }
IoFileObjectType, else
UserMode); {
#endif DeviceObject = IoGetRelatedDeviceObject(FileObject);
KeResetEvent( &FileObject->Event ); }
Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize, TRUE); /* Clear and set up Events */
if (Irp == NULL) KeClearEvent(&FileObject->Event);
{ KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
/*
* FIXME: This case should eventually be handled. We should wait /* Allocate an IRP */
* until enough memory is available to allocate the IRP. Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
*/
ASSERT(FALSE); /* Set it up */
} Irp->UserEvent = &Event;
Irp->UserIosb = &IoStatusBlock;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject= FileObject;
Irp->Flags = IRP_CLOSE_OPERATION | IRP_SYNCHRONOUS_API;
/* Set up Stack Pointer Data */
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = IRP_MJ_CLOSE;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = FileObject;
Irp->UserEvent = &FileObject->Event; /* Call the FS Driver */
Irp->Tail.Overlay.Thread = PsGetCurrentThread(); Status = IoCallDriver(DeviceObject, Irp);
Irp->Flags |= IRP_CLOSE_OPERATION;
/* Wait for completion */
StackPtr = IoGetNextIrpStackLocation(Irp); if (Status == STATUS_PENDING)
StackPtr->MajorFunction = IRP_MJ_CLOSE; {
StackPtr->DeviceObject = FileObject->DeviceObject; KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
StackPtr->FileObject = FileObject; }
Status = IoCallDriver(FileObject->DeviceObject, Irp); /* Clear the file name */
if (Status == STATUS_PENDING) if (FileObject->FileName.Buffer)
{ {
KeWaitForSingleObject(&FileObject->Event, Executive, KernelMode, FALSE, NULL); ExFreePool(FileObject->FileName.Buffer);
} FileObject->FileName.Buffer = NULL;
} }
if (FileObject->FileName.Buffer != NULL) /* Free the completion context */
{ if (FileObject->CompletionContext)
ExFreePool(FileObject->FileName.Buffer); {
FileObject->FileName.Buffer = 0; ObDereferenceObject(FileObject->CompletionContext->Port);
} ExFreePool(FileObject->CompletionContext);
}
}
} }
static static