Prevent infinite loop when using on-quit (#1856)

This commit is contained in:
Joe Lim authored and GitHub committed 2024-11-17 23:10:20 +11:00
1 parent f0dddccb04
commit 68a29c9284
1 file changed
+9
+9
View File
@@ -35,6 +35,7 @@ type app struct {
menuCompInd int menuCompInd int
selectionOut []string selectionOut []string
watch *watch watch *watch
quitting bool
} }
func newApp(ui *ui, nav *nav) *app { func newApp(ui *ui, nav *nav) *app {
@@ -66,6 +67,14 @@ func newApp(ui *ui, nav *nav) *app {
} }
func (app *app) quit() { func (app *app) quit() {
// Using synchronous shell commands for `on-quit` can cause this to be
// called again, so a guard variable is introduced here to prevent an
// infinite loop.
if app.quitting {
return
}
app.quitting = true
onQuit(app) onQuit(app)
if gOpts.history { if gOpts.history {