Skip to content

Avoid clearing com_array object representation - #1642

Open
Daniel Jump (DanielJump) wants to merge 2 commits into
microsoft:masterfrom
DanielJump:fix-com-array-detach
Open

Daniel Jump (DanielJump) wants to merge 2 commits into
microsoft:masterfrom
DanielJump:fix-com-array-detach

Conversation

@DanielJump

@DanielJump Daniel Jump (DanielJump) commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • replace memset of the non-trivially-copyable com_array object with explicit data and size resets
  • share the ownership-release logic across the MSVC and non-MSVC result-construction paths
  • add a focused test covering detach ownership, source reset, and retained array contents

The existing MSVC std::pair padding workaround remains unchanged.

Validation

  • x64 Debug solution build
  • test_old.exe '*detach*': 18 assertions in 5 test cases passed
  • patch formatting and line endings checked

Reset the detached array's data and size members explicitly so detach_abi does not write through the representation of a non-trivially-copyable object.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c
Hostname: DanJump0
Reset the com_array members after the compiler-specific result construction so both paths use the same ownership-release logic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c
Hostname: DanJump0

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The detach test checks only emptiness, not whether the source pointer is null, leaving a potential double-free regression undetected.

1 open issue
What changed in this PR

Updates C++/WinRT’s com_array detachment to reset its fields explicitly rather than clearing the object representation with memset.

Changes:

  • Shares pointer and size resets across compiler paths while preserving the MSVC std::pair padding workaround.
  • Adds a focused test for ownership transfer, source emptiness, and retained array contents.
File Description
test/​old_tests/​UnitTests/​array.cpp Adds a com_array detach test.
strings/​base_array.h Replaces object-wide clearing with shared field resets.

Review effort: Max

auto detached = detach_abi(a);
com_array<int> b(detached.second, detached.first, take_ownership_from_abi);

REQUIRE(a.empty());
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.

2 participants