From e83557fa58f0ec96f98f7bca09220dd0d50bc2d2 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 5 Feb 2005 08:44:49 +0000 Subject: [PATCH] Dynamically reallocate the buffer for PnP event if it's too small. svn path=/trunk/; revision=13418 --- reactos/services/umpnpmgr/umpnpmgr.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/reactos/services/umpnpmgr/umpnpmgr.c b/reactos/services/umpnpmgr/umpnpmgr.c index 25a3d107bab..bb9ce0a797c 100644 --- a/reactos/services/umpnpmgr/umpnpmgr.c +++ b/reactos/services/umpnpmgr/umpnpmgr.c @@ -65,10 +65,12 @@ static DWORD WINAPI PnpEventThread(LPVOID lpParameter) { PPLUGPLAY_EVENT_BLOCK PnpEvent; + ULONG PnpEventSize; NTSTATUS Status; RPC_STATUS RpcStatus; - PnpEvent = HeapAlloc(GetProcessHeap(), 0, 1024); + PnpEventSize = 0x1000; + PnpEvent = HeapAlloc(GetProcessHeap(), 0, PnpEventSize); if (PnpEvent == NULL) return ERROR_OUTOFMEMORY; @@ -76,10 +78,17 @@ PnpEventThread(LPVOID lpParameter) { DPRINT("Calling NtGetPlugPlayEvent()\n"); - ZeroMemory(PnpEvent, 1024); - /* Wait for the next pnp event */ Status = NtGetPlugPlayEvent(0, 0, PnpEvent, 1024); + /* Resize the buffer for the PnP event if it's too small. */ + if (Status == STATUS_BUFFER_TOO_SMALL) + { + PnpEventSize += 0x400; + PnpEvent = HeapReAlloc(GetProcessHeap(), 0, PnpEvent, PnpEventSize); + if (PnpEvent == NULL) + return ERROR_OUTOFMEMORY; + continue; + } if (!NT_SUCCESS(Status)) { DPRINT("NtPlugPlayEvent() failed (Status %lx)\n", Status); @@ -87,7 +96,7 @@ PnpEventThread(LPVOID lpParameter) } DPRINT("Received PnP Event\n"); - if (UuidEqual((UUID*)&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, &RpcStatus)) + if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, &RpcStatus)) { DPRINT1("Device arrival event: %S\n", PnpEvent->TargetDevice.DeviceIds); } @@ -98,7 +107,6 @@ PnpEventThread(LPVOID lpParameter) /* FIXME: Process the pnp event */ - /* Dequeue the current pnp event and signal the next one */ NtPlugPlayControl(PLUGPLAY_USER_RESPONSE, NULL, 0); }