From a3e2c4bb4f0cc7f1ff96631abceeb01158d338a5 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sun, 5 Apr 2009 16:39:51 +0000 Subject: [PATCH] - Check if allocation of work item succeeded - Thanks Ged, aicom - Fix leaking of a work item on close event / irp stream run out svn path=/trunk/; revision=40375 --- .../wdm/audio/backpln/portcls/adapter.c | 22 ++++++++++ .../audio/backpln/portcls/pin_wavecyclic.c | 44 ++++++++++--------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/reactos/drivers/wdm/audio/backpln/portcls/adapter.c b/reactos/drivers/wdm/audio/backpln/portcls/adapter.c index 8ea63f32e71..c420d69083a 100644 --- a/reactos/drivers/wdm/audio/backpln/portcls/adapter.c +++ b/reactos/drivers/wdm/audio/backpln/portcls/adapter.c @@ -135,6 +135,13 @@ PcAddAdapterDevice( /* allocate create item */ portcls_ext->CreateItems = AllocateItem(NonPagedPool, MaxObjects * sizeof(KSOBJECT_CREATE_ITEM), TAG_PORTCLASS); + if (!portcls_ext->CreateItems) + { + /* not enough resources */ + IoDeleteDevice(fdo); + return STATUS_INSUFFICIENT_RESOURCES; + } + /* store the physical device object */ portcls_ext->PhysicalDeviceObject = PhysicalDeviceObject; /* set up the start device function */ @@ -152,6 +159,17 @@ PcAddAdapterDevice( /* allocate work item */ portcls_ext->WorkItem = IoAllocateWorkItem(fdo); + if (!portcls_ext->WorkItem) + { + /* not enough resources */ + FreeItem(portcls_ext->CreateItems, TAG_PORTCLASS); + /* delete created fdo */ + IoDeleteDevice(fdo); + /* return error code */ + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* allocate the device header */ status = KsAllocateDeviceHeader(&portcls_ext->KsDeviceHeader, MaxObjects, portcls_ext->CreateItems); /* did we succeed */ @@ -159,6 +177,8 @@ PcAddAdapterDevice( { /* free previously allocated create items */ FreeItem(portcls_ext->CreateItems, TAG_PORTCLASS); + /* free allocated work item */ + IoFreeWorkItem(portcls_ext->WorkItem); /* delete created fdo */ IoDeleteDevice(fdo); /* return error code */ @@ -180,6 +200,8 @@ PcAddAdapterDevice( KsFreeDeviceHeader(portcls_ext->KsDeviceHeader); /* free previously allocated create items */ FreeItem(portcls_ext->CreateItems, TAG_PORTCLASS); + /* free allocated work item */ + IoFreeWorkItem(portcls_ext->WorkItem); /* delete created fdo */ IoDeleteDevice(fdo); /* return error code */ diff --git a/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c b/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c index 7a44790f334..84e939ebdb1 100644 --- a/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c +++ b/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c @@ -215,21 +215,21 @@ StopStreamRoutine( IN PVOID SystemArgument1, IN PVOID SystemArgument2) { + PDEVICE_OBJECT DeviceObject; + PPCLASS_DEVICE_EXTENSION DeviceExtension; IPortPinWaveCyclicImpl * This = (IPortPinWaveCyclicImpl*)DeferredContext; - PIO_WORKITEM WorkItem; if (This->IrpQueue->lpVtbl->NumMappings(This->IrpQueue)) return; - WorkItem = IoAllocateWorkItem(GetDeviceObject(This->Port)); - if (!WorkItem) - return; - - IoQueueWorkItem(WorkItem, StopStreamWorkerRoutine, DelayedWorkQueue, (PVOID)This); + /* Get device object */ + DeviceObject = GetDeviceObject(This->Port); + /* Get device extension */ + DeviceExtension = (PPCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + /* queue the work item */ + IoQueueWorkItem(DeviceExtension->WorkItem, StopStreamWorkerRoutine, DelayedWorkQueue, (PVOID)This); } - - static VOID NTAPI @@ -249,7 +249,6 @@ IServiceSink_fnRequestService( return; } - Status = This->Stream->lpVtbl->GetPosition(This->Stream, &Position); DPRINT("Position %u Buffer %p BufferSize %u ActiveIrpOffset %u\n", Position, Buffer, This->CommonBufferSize, BufferSize); @@ -692,23 +691,26 @@ IPortPinWaveCyclic_fnClose( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { - PIO_WORKITEM WorkItem; - + PPCLASS_DEVICE_EXTENSION DeviceExtension; IPortPinWaveCyclicImpl * This = (IPortPinWaveCyclicImpl*)iface; if (This->Stream) { - WorkItem = IoAllocateWorkItem(DeviceObject); - if (WorkItem) + if (Irp) { - if (Irp) - { - This->CloseIrp = Irp; - IoMarkIrpPending(Irp); - Irp->IoStatus.Information = 0; - Irp->IoStatus.Status = STATUS_PENDING; - } - IoQueueWorkItem(WorkItem, CloseStreamRoutine, DelayedWorkQueue, (PVOID)This); + This->CloseIrp = Irp; + IoMarkIrpPending(Irp); + Irp->IoStatus.Information = 0; + Irp->IoStatus.Status = STATUS_PENDING; + } + /* Get device extension */ + DeviceExtension = (PPCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + /* defer work item */ + IoQueueWorkItem(DeviceExtension->WorkItem, CloseStreamRoutine, DelayedWorkQueue, (PVOID)This); + + if (Irp) + { + /* The WaveCyclic filter passes close request with NULL / IRP */ return STATUS_PENDING; } }