Skip to content

Retain CFRunLoopRef to prevent use-after-free in FsEventWatcher::stop#2

Merged
Anthony-Eid merged 1 commit intoupstream-merge-8.2.0from
fix-cur-runloop-panic
Feb 16, 2026
Merged

Retain CFRunLoopRef to prevent use-after-free in FsEventWatcher::stop#2
Anthony-Eid merged 1 commit intoupstream-merge-8.2.0from
fix-cur-runloop-panic

Conversation

@Anthony-Eid
Copy link

FsEventWatcher::run() sends a non-retained CFRunLoopRef from the watcher thread back to the caller. If the watcher thread exits before stop() is called (e.g., the runloop has no sources), the runloop object is freed with the thread, leaving a dangling pointer. stop() then crashes in CFRunLoopIsWaiting on the freed ref.

Fix: call CFRetain on the runloop before sending it across the channel, and CFRelease in stop() after joining the thread. This keeps the runloop object alive for the entire window between run() and stop().

Note: Claude Opus generated this PR, but I reviewed it locally and this fixed a crash that was occurring on Zed's end

`FsEventWatcher::run()` sends a non-retained `CFRunLoopRef` from the
watcher thread back to the caller. If the watcher thread exits before
`stop()` is called (e.g., the runloop has no sources), the runloop
object is freed with the thread, leaving a dangling pointer. `stop()`
then crashes in `CFRunLoopIsWaiting` on the freed ref.

Fix: call `CFRetain` on the runloop before sending it across the
channel, and `CFRelease` in `stop()` after joining the thread. This
keeps the runloop object alive for the entire window between `run()` and
`stop()`.

Note: Claude Opus generated this PR, but I reviewed it locally and this
fixed a crash that was occurring on Zed's end
@Anthony-Eid Anthony-Eid merged commit ce58c24 into upstream-merge-8.2.0 Feb 16, 2026
Anthony-Eid added a commit to zed-industries/zed that referenced this pull request Feb 16, 2026
Anthony-Eid added a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code
github-actions bot pushed a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code
github-actions bot pushed a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code
zed-zippy bot added a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
…pick to stable) (#49339)

Cherry-pick of #49311 to stable

----
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code

Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
zed-zippy bot added a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
…pick to preview) (#49338)

Cherry-pick of #49311 to preview

----
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code

Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
rtfeldman pushed a commit to zed-industries/zed that referenced this pull request Feb 17, 2026
Closes #49067

See zed-industries/notify#2 for more details

Note: notify already fixed this upstream, and I'm planning on using
their crate as our dependency once their v9 is officially released.

Release Notes:

- Fix panic that could occur when navigating external code
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.

1 participant