Release managed WTS plugin reference when registration fails - #190
Merged
Marc-André Moreau (mamoreau-devolutions) merged 1 commit intoSep 24, 2026
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Marc-André Moreau (mamoreau-devolutions)
September 24, 2026 10:48
View session
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The ownership logic matches the native contract, and focused tests cover both transfer outcomes.
Review effort: Balanced
Findings: None
What changed in this PR
Ensures managed WTS plugin references are released when COM registration fails while preserving native ownership transfer on success.
Changes:
- Adds exception-safe
IUnknowncleanup. - Adds headless tests for failure and success paths.
| File | Description |
|---|---|
dotnet/Devolutions.MsRdpEx/RdpInstance.cs |
Releases ownership unless registration succeeds. |
dotnet/MsRdpEx_Test/RdpInstancePluginTests.cs |
Verifies reference-count behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Marc-André Moreau (mamoreau-devolutions)
merged commit Sep 24, 2026
0ab7dd2
into
master
1 check passed
Marc-André Moreau (mamoreau-devolutions)
added a commit
that referenced
this pull request
Sep 24, 2026
## Summary - Capture the session GUID rather than a borrowed native instance pointer in the DVC class factory; a removed session returns `REGDB_E_CLASSNOTREG`. - Pin registered plugins with an internal reference holder, so plugin COM `AddRef`/`Release` and `QueryInterface` run **outside** the instance and registry locks. The borrowed getter and success-only ownership-transfer setter ABI—including same-pointer replacement—remain unchanged. If holder allocation fails, the caller retains its incoming reference, matching #190. - Synchronize the production `DllGetClassObject` session lookup and factory plugin acquisition with manager teardown. Keep manager destruction and plugin releases outside the global lock. - **Detach and close the instance's plugin slot before final destructor release.** Reentrant plugin callbacks observe an empty getter; setters reject registration with `E_UNEXPECTED` and preserve caller ownership. This closes the previously identified destructor reentrancy use-after-free/double-release path. - Test removal, replacement during `QueryInterface`, reentrant `AddRef`/`Release`, destructor reentrancy, manager shutdown during an in-flight factory call, deterministic allocation failure (including same-pointer retry), and failed plugin `QueryInterface` without connecting RDP. ## Validation - Native x64 CMake/Ninja build (DLL, launchers, and tests): passed against current `master` after integrating #190 and #191. - `ctest --test-dir build-dvc-x64 --output-on-failure`: **31/31 passed**, including `logging.dvc-factory.destructor-reentrant` and the detached-instance regression from #191. A plugin callback using a raw instance pointer after the instance's final COM `Release` is outside the normal COM lifetime contract; this regression specifically guards synchronous reentry during native teardown. Local build used an **ignored, untracked** `build-dvc-x64/stubs/atlbase.h` compatibility shim because this VS2026 installation lacks ATL. Nothing from the shim, package versions, or workflows is included. Validation with the full ATL toolchain or a live RDP connection remains outstanding. No change to the original mstscax `pUnknown` release behavior. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IUnknownreference owned untilSetWTSPluginObjectreturns successfully; release it infinallyif the COM call throws.IMsRdpExInstance.Validation
dotnet build dotnet\Devolutions.MsRdpEx\Devolutions.MsRdpEx.csproj --framework net48 --no-restore --verbosity quiet -p:WarningLevel=0dotnet build dotnet\Devolutions.MsRdpEx\Devolutions.MsRdpEx.csproj --framework net8.0-windows --no-restore --verbosity quiet -p:WarningLevel=0dotnet test dotnet\MsRdpEx_Test\MsRdpEx_Test.csproj --no-build --filter "FullyQualifiedName~MsRdpEx.Tests.RdpInstancePluginTests" --verbosity quiet— 2 passed, 0 failed.No native COM registration or RDP client is required by the tests.