You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the issue
I observed an ongoing unmanaged memory leak when regularly polling for connected devices. I reproduced it with a minimal CLI .exe and narrowed it down to WindowsHidApiService.GetHidCapabilities. To resolve the leak, change the HidD_FreePreparsedDatapointerToPreparsedData parameter to not be ref.
Describe the issue
I observed an ongoing unmanaged memory leak when regularly polling for connected devices. I reproduced it with a minimal CLI .exe and narrowed it down to
WindowsHidApiService.GetHidCapabilities
. To resolve the leak, change theHidD_FreePreparsedData
pointerToPreparsedData
parameter to not beref
.The
HidD_GetPreparsedData
documentation shows a*PreparsedData
parameter. This matches with theout
parameter option used.https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidsdi/nf-hidsdi-hidd_getpreparseddata
The
HidD_FreePreparsedData
documentation shows aPreparsedData
parameter with no dereference. I believe it should therefore be called withoutref
.https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidsdi/nf-hidsdi-hidd_freepreparseddata
Relevant call stack -
WindowsHidApiService.GetHidCapabilities
WindowsHidApiService.GetDeviceDefinition
WindowsHidDeviceFactoryExtensions.GetDeviceDefinition
WindowsDeviceEnumerator.GetConnectedDeviceDefinitionsAsync
Screenshots
Memory profiler running for one minute. Notice the bottom-right section for unmanaged memory breakdown by module.
without fix
with fix
Your Code
The memory leak can be reproduced easily.
The leak can be resolved with two changes.
Device.Net/src/Hid.Net/Windows/WindowsHidApiService.cs
Line 61 in 417330e
Device.Net/src/Hid.Net/Windows/WindowsHidApiService.cs
Line 117 in 417330e
Log / Stack Trace
No relevant logging or stack trace.
Info
PR coming soon.
The text was updated successfully, but these errors were encountered: