From 5ae7a23e1ec99f1e552967ed9d058133b6c860c6 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 9 Mar 2023 22:44:03 +0100 Subject: account: fix crash/race on init When an account is initialized too quickly, setTitle may be called before acct.tab is initialized, leading to a crash: runtime error: invalid memory address or nil pointer dereference goroutine 1 [running]: panic({0xa49820, 0x1059510}) runtime/panic.go:890 +0x262 git.sr.ht/~rjarry/aerc/lib/ui.(*Tab).SetTitle(...) git.sr.ht/~rjarry/aerc/lib/ui/tab.go:37 git.sr.ht/~rjarry/aerc/widgets.(*AccountView).setTitle(0xc000838000) git.sr.ht/~rjarry/aerc/widgets/account.go:617 +0x2a0 git.sr.ht/~rjarry/aerc/widgets.(*AccountView).onMessage(0xc000838000, {0xbffc60?, 0xc0000f1080?}) git.sr.ht/~rjarry/aerc/widgets/account.go:364 +0x13e8 git.sr.ht/~rjarry/aerc/widgets.(*Aerc).HandleMessage(0xc0000f4000, {0xbffc60, 0xc0000f1080}) git.sr.ht/~rjarry/aerc/widgets/aerc.go:174 +0x5f main.main() git.sr.ht/~rjarry/aerc/aerc.go:252 +0x965 Avoid this. Fixes: 6b39c0dae1e1 ("tabs: use template for account tab name") Signed-off-by: Robin Jarry --- widgets/account.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/widgets/account.go b/widgets/account.go index 5b5d4dcd..fdd33301 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -604,6 +604,9 @@ func (acct *AccountView) Vsplit(n int) error { func (acct *AccountView) setTitle() { var data state.TemplateData + if acct.tab == nil { + return + } data.SetAccount(acct.acct) data.SetFolder(acct.SelectedDirectory()) data.SetRUE(acct.dirlist.List(), acct.dirlist.GetRUECount) -- cgit