Unloading a Windows Driver

I am creating a Network driver using Windows KMDF Driver and Windows Filtering Platform(WFP) API.

While unloading the driver, I should deallocate all the memory allocated by the driver to avoid memory leaks.

I have an object X which gets allocated and deallocated within Driver itself. There is no problem with that object.

I have another object Y which is getting allocated in Driver using ExAllocatePoolWithTag() and I am setting that address in localRedirectContext of FWPS_CONNECT_REQUEST0 struct.

And then I am fetching that data using WSAIoctl and using it in the User-mode application. Should I need to handle the deallocation of object Y. But if I deallocate the object Y, it throws an error in WinDbg, so I assumed that it should not be deallocated.

Am I doing it correct or not?

Note Starting with Windows 8, memory allocated for localRedirectContext will have its ownership taken by WFP, and will be freed when the proxied flow is removed.

Always read the docs. https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/fwpsk/ns-fwpsk-_fwps_connect_request0
Sometimes the docs are less than clear, but in this case they are concise.

1 Like