Skip to content

[serial/VirtualSerial2] Complete WDFREQUEST on error paths in EvtIoWrite - #1422

Open
RKS (rksharma-owg) wants to merge 1 commit into
microsoft:mainfrom
rksharma-owg:fix/virtualserial2-evt-io-write-leak
Open

RKS (rksharma-owg) wants to merge 1 commit into
microsoft:mainfrom
rksharma-owg:fix/virtualserial2-evt-io-write-leak

Conversation

@rksharma-owg

Copy link
Copy Markdown

Description

In serial/VirtualSerial2/queue.c, the EvtIoWrite callback receives a WDFREQUEST Request from the framework.

Prior to this change, if WdfRequestRetrieveInputMemory fails (e.g., memory allocation failure) or if QueueProcessWriteBytes fails (e.g., invalid write parameters), EvtIoWrite logged an error trace and executed return; without completing, forwarding, or storing the Request.

Under the Windows Driver Framework (KMDF), the driver is responsible for completing any request delivered to an I/O event callback unless the request is forwarded to another queue or marked cancelable/stored. Returning without completing the request causes the caller to hang indefinitely waiting for I/O completion and leaks the request object and associated framework resources.

This change calls WdfRequestComplete(Request, status); before returning on both error exit paths in EvtIoWrite, matching KMDF request handling conventions and the error handling pattern used in EvtIoRead and EvtIoDeviceControl.

Fixes #1375

Validation

  • Environment: GitHub Actions runner windows-2025-vs2026 (VS 2026 / WDK build environment)
  • Build Tool: .\Build-Samples.ps1
  • Command:
    .\Build-Samples.ps1 -Samples "serial.virtualserial2" -Configurations Debug,Release -Platforms x64,arm64 -Verbose
  • Results:
    • serial.virtualserial2 Debug x64: Succeeded (0 errors, 0 warnings)
    • serial.virtualserial2 Release x64: Succeeded (0 errors, 0 warnings)
    • serial.virtualserial2 Debug arm64: Succeeded (0 errors, 0 warnings)
    • serial.virtualserial2 Release arm64: Succeeded (0 errors, 0 warnings)
    • Total: 4 targets built, 4 succeeded, 0 failed

Ensure incoming write requests are completed with their failure NTSTATUS
when WdfRequestRetrieveInputMemory or QueueProcessWriteBytes fails,
preventing request leaks and caller hangs.

Fixes microsoft#1375
@rksharma-owg
RKS (rksharma-owg) requested a review from a team as a code owner September 17, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[/serial/serial/VirtualSerial2]: Potential memory leak?

1 participant