Author: janderwald Date: Sun Apr 5 20:05:54 2009 New Revision: 40373
URL: http://svn.reactos.org/svn/reactos?rev=40373&view=rev Log: - Fix leaking of work item for each detected audio device
Modified: trunk/reactos/drivers/wdm/audio/sysaudio/deviface.c trunk/reactos/drivers/wdm/audio/sysaudio/main.c
Modified: trunk/reactos/drivers/wdm/audio/sysaudio/deviface.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/sysaudio/... ============================================================================== --- trunk/reactos/drivers/wdm/audio/sysaudio/deviface.c [iso-8859-1] (original) +++ trunk/reactos/drivers/wdm/audio/sysaudio/deviface.c [iso-8859-1] Sun Apr 5 20:05:54 2009 @@ -17,7 +17,7 @@ NTAPI FilterPinWorkerRoutine( IN PDEVICE_OBJECT DeviceObject, - IN PVOID Context) + IN PVOID Context) { KSPROPERTY PropertyRequest; KSP_PIN PinRequest; @@ -27,6 +27,7 @@ ULONG Count, Index; NTSTATUS Status; ULONG BytesReturned; + PSYSAUDIODEVEXT DeviceExtension; PKSAUDIO_DEVICE_ENTRY DeviceEntry = (PKSAUDIO_DEVICE_ENTRY)Context;
@@ -40,17 +41,22 @@ Status = KsSynchronousIoControlDevice(DeviceEntry->FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)&PropertyRequest, sizeof(KSPROPERTY), (PVOID)&Count, sizeof(ULONG), &BytesReturned); if (!NT_SUCCESS(Status)) { + ExFreePool(DeviceEntry); return; }
if (!Count) + { + ExFreePool(DeviceEntry); return; + }
/* allocate pin array */ DeviceEntry->Pins = ExAllocatePool(NonPagedPool, Count * sizeof(PIN_INFO)); if (!DeviceEntry->Pins) { /* no memory */ + ExFreePool(DeviceEntry); return; } /* clear array */ @@ -96,6 +102,12 @@ }
DPRINT1("Num Pins %u Num WaveIn Pins %u Name WaveOut Pins %u\n", DeviceEntry->NumberOfPins, DeviceEntry->NumWaveInPin, DeviceEntry->NumWaveOutPin); + + DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension; + + InsertTailList(&DeviceExtension->KsAudioDeviceList, &DeviceEntry->Entry); + DeviceExtension->NumberOfKsAudioDevices++; + }
NTSTATUS @@ -153,6 +165,7 @@ DEVICE_INTERFACE_CHANGE_NOTIFICATION * Event; NTSTATUS Status = STATUS_SUCCESS; PSYSAUDIODEVEXT DeviceExtension; + PKSAUDIO_DEVICE_ENTRY DeviceEntry; PDEVICE_OBJECT DeviceObject = (PDEVICE_OBJECT)Context;
DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension; @@ -163,10 +176,6 @@ &GUID_DEVICE_INTERFACE_ARRIVAL)) { /* a new device has arrived */ - - PKSAUDIO_DEVICE_ENTRY DeviceEntry; - PIO_WORKITEM WorkItem; - DeviceEntry = ExAllocatePool(NonPagedPool, sizeof(KSAUDIO_DEVICE_ENTRY)); if (!DeviceEntry) { @@ -206,16 +215,11 @@ return Status; }
- DPRINT1("Successfully opened audio device %u handle %p file object %p device object %p\n", DeviceExtension->KsAudioDeviceList, DeviceEntry->Handle, DeviceEntry->FileObject, DeviceEntry->FileObject->DeviceObject); - DeviceExtension->NumberOfKsAudioDevices++; - - WorkItem = IoAllocateWorkItem(DeviceObject); - if (WorkItem) - { - IoQueueWorkItem(WorkItem, FilterPinWorkerRoutine, DelayedWorkQueue, (PVOID)DeviceEntry); - } - InsertTailList(&DeviceExtension->KsAudioDeviceList, &DeviceEntry->Entry); - + DPRINT1("Successfully opened audio device %u handle %p file object %p device object %p\n", DeviceExtension->NumberOfKsAudioDevices, DeviceEntry->Handle, DeviceEntry->FileObject, DeviceEntry->FileObject->DeviceObject); + + //FIXME + // mutal exclusion + IoQueueWorkItem(DeviceExtension->WorkItem, FilterPinWorkerRoutine, DelayedWorkQueue, (PVOID)DeviceEntry); return Status; } else
Modified: trunk/reactos/drivers/wdm/audio/sysaudio/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/sysaudio/... ============================================================================== --- trunk/reactos/drivers/wdm/audio/sysaudio/main.c [iso-8859-1] (original) +++ trunk/reactos/drivers/wdm/audio/sysaudio/main.c [iso-8859-1] Sun Apr 5 20:05:54 2009 @@ -131,6 +131,22 @@ goto cleanup; }
+ /* allocate work item */ + DeviceExtension->WorkItem = IoAllocateWorkItem(DeviceObject); + if (!DeviceExtension->WorkItem) + { + DPRINT1("Failed to allocate work item\n"); + goto cleanup; + } + + /* allocate work item context */ + DeviceExtension->WorkerContext = ExAllocatePool(NonPagedPool, sizeof(PIN_WORKER_CONTEXT)); + if (!DeviceExtension->WorkerContext) + { + DPRINT1("Failed to allocate work item context\n"); + goto cleanup; + } + /* Register device notification hooks */ Status = SysAudioRegisterNotifications(DriverObject, DeviceObject); @@ -139,23 +155,6 @@ DPRINT1("Failed to register device notifications\n"); goto cleanup; } - - /* allocate work item */ - DeviceExtension->WorkItem = IoAllocateWorkItem(DeviceObject); - if (!DeviceExtension->WorkItem) - { - DPRINT1("Failed to allocate work item\n"); - goto cleanup; - } - - /* allocate work item context */ - DeviceExtension->WorkerContext = ExAllocatePool(NonPagedPool, sizeof(PIN_WORKER_CONTEXT)); - if (!DeviceExtension->WorkerContext) - { - DPRINT1("Failed to allocate work item context\n"); - goto cleanup; - } -
/* Load kmixer */ Status = SysAudioOpenKMixer(DeviceExtension);