Fix use-after-free in ghostty_surface_refresh after sleep/wake (#432) (#619)

Add nil guard in forceRefresh() to prevent dereferencing freed surface
pointer. Split else-if chains in Workspace.swift so
requestBackgroundSurfaceStartIfNeeded() runs if surface is freed during
the refresh call. Add regression test exercising the crash path.
This commit is contained in:
Lawrence Chen 2026-02-27 01:44:02 -08:00 committed by GitHub
parent 9ae737026d
commit dca8992901
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 80 additions and 16 deletions

View file

@ -3083,8 +3083,10 @@ final class Workspace: Identifiable, ObservableObject {
// layout and view lifecycle changes that free surfaces (#432).
if terminalPanel.surface.surface != nil {
terminalPanel.surface.forceRefresh()
} else if isAttached && hasUsableBounds {
}
if terminalPanel.surface.surface == nil, isAttached && hasUsableBounds {
terminalPanel.surface.requestBackgroundSurfaceStartIfNeeded()
needsFollowUpPass = true
}
}
@ -3139,7 +3141,8 @@ final class Workspace: Identifiable, ObservableObject {
panel.hostedView.reconcileGeometryNow()
if panel.surface.surface != nil {
panel.surface.forceRefresh()
} else {
}
if panel.surface.surface == nil {
panel.surface.requestBackgroundSurfaceStartIfNeeded()
}
}