From 3726782f687c7166ed81f7f22de1c026ebb96fc3 Mon Sep 17 00:00:00 2001 From: Darren O'Connor Date: Sat, 30 Oct 2021 09:52:55 -0400 Subject: [PATCH] Use defers for locks --- lib/server.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/server.go b/lib/server.go index f564bec..a38f43a 100644 --- a/lib/server.go +++ b/lib/server.go @@ -339,13 +339,14 @@ func (s *Server) setSerial(serial uint32) { // be called before the VRPs data is added. func (s *Server) SetSerial(serial uint32) { s.vrplock.RLock() + defer s.vrplock.RUnlock() //s.vrpListSerial = make([]uint32, 0) s.setSerial(serial) - s.vrplock.RUnlock() } func (s *Server) AddVRPs(vrps []VRP) { s.vrplock.RLock() + defer s.vrplock.RUnlock() vrpCurrent := s.vrpCurrent @@ -356,7 +357,6 @@ func (s *Server) AddVRPs(vrps []VRP) { s.log.Debugf("Computed diff: added (%d), removed (%d), unchanged (%d)", len(added), len(removed), len(unchanged)) } curDiff := append(added, removed...) - s.vrplock.RUnlock() s.AddVRPsDiff(curDiff) } @@ -383,6 +383,7 @@ func (s *Server) AddVRPsDiff(diff []VRP) { s.vrplock.RUnlock() s.vrplock.Lock() + defer s.vrplock.Unlock() newserial := s.generateSerial() removed := s.addSerial(newserial) @@ -407,7 +408,6 @@ func (s *Server) AddVRPsDiff(diff []VRP) { s.vrpListDiff = nextDiff s.vrpCurrent = newVrpCurrent s.setSerial(newserial) - s.vrplock.Unlock() } func (s *Server) SetBaseVersion(version uint8) { @@ -956,7 +956,6 @@ func (c *Client) Disconnect() { select { case c.quit <- true: default: - } c.tcpconn.Close()