From 08d99d776d359aa1ef056e4455f82d92b6940507 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 27 Apr 2019 15:11:38 +0300 Subject: [PATCH] Fix potential deadlock in room switching --- ui/room-list.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/room-list.go b/ui/room-list.go index 0dc3e74..6b22c8e 100644 --- a/ui/room-list.go +++ b/ui/room-list.go @@ -438,11 +438,11 @@ func (list *RoomList) clickRoom(line, column int, mod bool) bool { return false } list.RLock() - defer list.RUnlock() for _, tag := range list.tags { trl := list.items[tag] if line--; line == -1 { trl.ToggleCollapse() + list.RUnlock() return true } @@ -453,7 +453,9 @@ func (list *RoomList) clickRoom(line, column int, mod bool) bool { if line < 0 { break } else if line < trl.Length() { - list.parent.SwitchRoom(tag, trl.Visible()[trl.Length()-1-line].Room) + switchToRoom := trl.Visible()[trl.Length()-1-line].Room + list.RUnlock() + list.parent.SwitchRoom(tag, switchToRoom) return true } @@ -482,6 +484,7 @@ func (list *RoomList) clickRoom(line, column int, mod bool) bool { // Tag footer line-- } + list.RUnlock() return false }