Skip to content

fix: memory leak in ua::Array::move_into_raw - #356

Merged
uklotzde merged 13 commits into
HMIProject:mainfrom
cartercanedy:cc/plumbing
Oct 21, 2026
Merged

uklotzde merged 13 commits into
HMIProject:mainfrom
cartercanedy:cc/plumbing

Conversation

@cartercanedy

Copy link
Copy Markdown
Contributor

Closes #355

Summary

  • move_into_raw now calls move_from_raw_parts on the destination array, which properly cleans up the array that's going to be clobbered
  • reworks the internal-only from_iter implementation into an internal-only trait that enables cleaner collection of iterators into ua::Array and updates existing callsites
    • note: I think that this private trait + impl for ua::Array should eventually become a public implementation of the FromIterator trait, relying on Iterator::size_hint to perform optimistic preallocations while remaining sound

@sgoll sgoll 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.

Thank you for your pull request 🎉

I have only a few minor remarks, see below. And do you think it would be possible to add a test case that reproduces the memory leak—so that it fails without the fix and does not fail anymore now?1

Footnotes

  1. I'm not sure it can be done easily, because it would involve showing that a destructor is not run, which with Rust code would be relatively easy (writing a sentinel value in impl Drop), but not so with the foreign types we are dealing with here. But if anything came to mind… 😇 ↩

Comment thread src/ua/array.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/ua/array.rs
Comment thread src/ua/array.rs
Comment thread src/ua/array.rs Outdated
Comment thread src/ua/array.rs Outdated
Comment thread src/lib.rs
@cartercanedy

cartercanedy commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

I have only a few minor remarks, see below. And do you think it would be possible to add a test case that reproduces the memory leak—so that it fails without the fix and does not fail anymore now?

See #358, it's establishing the testing infrastructure to enable ASAN in CI, which actually found another leak.

Also, I added a test that sits behind --cfg asan and invokes ua::Array::move_into_raw, which would've failed before this patch, that's the best solution that I could think of.

@cartercanedy
cartercanedy requested a review from sgoll October 14, 2026 12:27
@sgoll

sgoll commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cartercanedy Thank you! Just so you know, @uklotzde and I are currently attending EuroRust, so it'll probably take until next week for us to review your PRs.

uklotzde
uklotzde previously approved these changes Oct 17, 2026
Comment thread src/lib.rs Outdated
@uklotzde

Copy link
Copy Markdown
Collaborator

Please add a changelog entry.

uklotzde
uklotzde previously approved these changes Oct 20, 2026

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 leak probe does not reclaim the transferred raw allocation and will report a leak.

1 open issue
What changed in this PR

Fixes an ownership leak in ua::Array::move_into_raw and updates internal iterator-based array construction.

Changes:

  • Cleans up existing destination arrays before replacement.
  • Replaces internal from_iter usage with collect_ua_array.
  • Adds an ASAN leak probe and documentation updates.
File Summary
src/​ua/​data_types/​node_attributes/​variable_attributes.rs Updates array construction.
src/​ua/​data_types/​delete_subscriptions_request.rs Updates array construction.
src/​ua/​data_types/​delete_monitored_items_request.rs Updates array construction.
src/​ua/​data_types/​content_filter_element.rs Updates array construction.
src/​ua/​data_types/​browse_next_request.rs Updates array construction.
src/​ua/​data_types/​application_description.rs Updates array construction.
src/​ua/​array.rs Fixes ownership transfer and adds iterator support and leak testing.
src/​ua.rs Re-exports the internal iterator helper.
src/​server.rs Updates URL collection.
src/​lib.rs Imports the iterator helper.
CHANGELOG.md Documents the memory leak fix.
Cargo.toml Registers the ASAN configuration.

Review effort: Lite

Comment thread src/ua/array.rs Outdated
uklotzde
uklotzde previously approved these changes Oct 21, 2026
@uklotzde

Copy link
Copy Markdown
Collaborator

@sgoll Ping.

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.

🟢 Approval recommended

The ownership change correctly cleans up replaced arrays, the iterator refactor preserves behavior, and no blocking issues remain.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Comment thread CHANGELOG.md Outdated
Comment thread Cargo.toml
Comment thread src/ua/array.rs Outdated
Comment thread src/ua/array.rs Outdated
Comment thread src/ua/array.rs Outdated
Co-authored-by: Sebastian Goll <1277035+sgoll@users.noreply.github.com>
@uklotzde
uklotzde merged commit 35a38a8 into HMIProject:main Oct 21, 2026
23 checks passed
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.

memory leak in ua::Array::move_into_raw

4 participants