Skip to content

Fix: Multitouch data handling memory safety#117

Merged
NullPointerDepressiveDisorder merged 2 commits intomainfrom
seer/fix/multitouch-memory-safety
Mar 5, 2026
Merged

Fix: Multitouch data handling memory safety#117
NullPointerDepressiveDisorder merged 2 commits intomainfrom
seer/fix/multitouch-memory-safety

Conversation

@sentry
Copy link
Contributor

@sentry sentry bot commented Mar 5, 2026

Description

Fixes MIDDLEDRAG-M. The issue was that: Rapid system sleep/wake cycles cause DeviceMonitor to double-free an object due to gPendingCleanup being prematurely released during new instance initialization.

  • Replaced manual UnsafeMutableRawPointer allocation and deallocation for touch data with Swift's Data type.
  • Eliminated potential use-after-free and double-free risks associated with manual memory management in asynchronous contexts.
  • Improved memory safety and stability of multitouch processing, particularly during rapid system state changes like sleep/wake cycles.
  • Leveraged Swift's automatic memory management for Data objects, simplifying lifetime management.

This fix was generated by Seer in Sentry, triggered by Karan Mohindroo. 👁️ Run ID: 11264006

Not quite right? Click here to continue debugging with Seer.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Refactor (code change that neither fixes a bug nor adds a feature)
  • 🧪 Test improvement

Related Issues

Fixes MIDDLEDRAG-M

Testing Performed

  • Tested with built-in trackpad
  • Tested with Magic Trackpad (if available)
  • Verified system gestures (Mission Control, etc.) still work
  • Tested in target apps (list any specific apps tested):

Checklist

  • My code follows the project's code style guidelines
  • I have tested my changes thoroughly
  • I have added comments for non-obvious logic
  • My changes don't break existing functionality
  • I have updated documentation if needed

Code Coverage

  • I have added tests for new functionality (where applicable)
  • My changes meet the 80% patch coverage requirement

Note: Codecov will automatically check patch coverage. PRs that don't meet the 80% threshold will fail the coverage check. Files in MiddleDragTests/, AppDelegate.swift, MiddleDragApp.swift, and UpdateManager.swift are excluded from coverage requirements.

Screenshots / Recordings

Additional Notes

@NullPointerDepressiveDisorder NullPointerDepressiveDisorder marked this pull request as ready for review March 5, 2026 22:23
Copilot AI review requested due to automatic review settings March 5, 2026 22:23
@sentry
Copy link
Contributor Author

sentry bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
MiddleDrag/Managers/MultitouchManager.swift 92.85% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a reported memory-safety issue in multitouch frame handling by changing how touch data is buffered across asynchronous processing on gestureQueue, aiming to prevent use-after-free/double-free scenarios during rapid sleep/wake cycles.

Changes:

  • Replaced manual UnsafeMutableRawPointer allocation/deallocation for touch-frame copies with Data.
  • Updated the async gestureQueue processing path to pass a pointer derived from Data into GestureRecognizer.processTouches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Karan Mohindroo <96403086+NullPointerDepressiveDisorder@users.noreply.github.com>
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder merged commit 1ce5971 into main Mar 5, 2026
6 checks passed
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder deleted the seer/fix/multitouch-memory-safety branch March 5, 2026 22:44
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