Fix clipboard heap corruption on Windows#215
Merged
ryanoneill merged 2 commits intomainfrom Mar 9, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
+ Coverage 92.08% 92.12% +0.03%
==========================================
Files 145 146 +1
Lines 12778 12774 -4
==========================================
+ Hits 11767 11768 +1
+ Misses 1011 1006 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
98417af to
88f1795
Compare
On Windows, arboard::Clipboard::new() initializes COM per call. When the test runner executes clipboard-touching tests from input_field and text_area in parallel threads, concurrent COM initialization/teardown corrupts the heap, causing STATUS_HEAP_CORRUPTION (0xc0000374). Fix: Extract clipboard access into a shared src/clipboard.rs module that caches the arboard::Clipboard context in a thread_local!. This eliminates repeated COM init/teardown and also removes the duplicated clipboard functions from input_field and text_area. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Thread-local caching was insufficient — concurrent Clipboard::new() from different threads still caused heap corruption. Switch to a process-global OnceLock<Mutex<Option<Clipboard>>> that creates exactly one clipboard context and serializes all access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
88f1795 to
655fa1b
Compare
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
arboard::Clipboard::new()initializes COM on Windows. Wheninput_fieldandtext_areatests run in parallel threads, concurrent COM init/teardown corrupts the heap, causingSTATUS_HEAP_CORRUPTION(0xc0000374).src/clipboard.rsmodule with athread_local!cachedarboard::Clipboardcontext. One COM initialization per thread, reused for the thread's lifetime.input_field/mod.rsandtext_area/mod.rs.What changed
src/clipboard.rssystem_clipboard_set/system_clipboard_getusing thread-local cachingsrc/lib.rsclipboardmodule (gated onclipboardfeature)src/component/input_field/mod.rssrc/component/text_area/mod.rssrc/component/text_area/update.rsTest plan
cargo test --all-features --libpasses (4086 tests)cargo test --all-features --docpasses (787 tests)cargo test --no-default-features --libpasses (793 tests)cargo clippy --all-features -- -D warningsclean🤖 Generated with Claude Code