Skip to content

Commit 48b5ea9

Browse files
v2: nil-guard Application.Quit so pre-Run shutdown doesn't panic (#5468)
a.application is only set inside Run() once app.CreateApp succeeds. Calling Quit() before Run() (or after Run() failed early at CreateApp) hits a nil receiver inside the inner closure and crashes the host process. Fix from the issue: guard the Shutdown() call. Closes #5452 Signed-off-by: Charlie Tonneslan <cst0520@gmail.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
1 parent 42e853d commit 48b5ea9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

v2/pkg/application/application.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ func (a *Application) Run() error {
7474
return err
7575
}
7676

77-
// Quit will shut down the application
77+
// Quit will shut down the application.
78+
//
79+
// Safe to call before Run, or after Run returns early (e.g. CreateApp failed).
80+
// Without the nil guard, Quit() in those situations dereferences an unset
81+
// a.application and crashes (#5452).
7882
func (a *Application) Quit() {
7983
a.shutdown.Do(func() {
80-
a.application.Shutdown()
84+
if a.application != nil {
85+
a.application.Shutdown()
86+
}
8187
})
8288
}
8389

website/src/pages/changelog.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
## [Unreleased]
1616

17+
### Fixed
18+
19+
- Fixed nil pointer crash in `application.Quit` when called before `Run` or after `Run` returned early [#5452](https://github.com/wailsapp/wails/issues/5452) by @c-tonneslan
20+
1721
## v2.12.0 - 2026-03-26
1822

1923
### Fixed

0 commit comments

Comments
 (0)