Implemented freeing context memory

This commit is contained in:
Benjamin Höglinger-Stelzer
2020-05-11 21:39:43 +02:00
parent 55b1ef6cfa
commit c981801a37
2 changed files with 20 additions and 0 deletions

View File

@@ -145,6 +145,8 @@ NTSTATUS ViGEm::Bus::Core::EmulationTargetPDO::PdoCreateDevice(WDFDEVICE ParentD
// Add common device data context
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&pdoAttributes, EMULATION_TARGET_PDO_CONTEXT);
pdoAttributes.EvtCleanupCallback = EvtDeviceContextCleanup;
status = WdfDeviceCreate(&DeviceInit, &pdoAttributes, &this->_PdoDevice);
if (!NT_SUCCESS(status))
{
@@ -308,6 +310,22 @@ NTSTATUS ViGEm::Bus::Core::EmulationTargetPDO::PdoCreateDevice(WDFDEVICE ParentD
return status;
}
VOID ViGEm::Bus::Core::EmulationTargetPDO::EvtDeviceContextCleanup(
IN WDFOBJECT Device
)
{
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_BUSPDO, "%!FUNC! Entry");
const auto ctx = EmulationTargetPdoGetContext(Device);
//
// PDO device object getting disposed, free context object
//
delete ctx->Target;
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_BUSPDO, "%!FUNC! Exit");
}
VOID ViGEm::Bus::Core::EmulationTargetPDO::SetSerial(ULONG Serial)
{
this->_SerialNo = Serial;