aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurtonQin <bobbqqin@gmail.com>2020-04-08 16:03:18 +0000
committerEmmanuel Odeke <emm.odeke@gmail.com>2020-04-08 16:19:51 +0000
commit4874835232322713f23d2f10c083ae6fa893868b (patch)
tree73136f819488067d1efeaef8f6ec3ea897c33ee0 /src
parent7a35d39b56dacf9ef248d3e77bc2f9e8147d6b75 (diff)
downloadgo-4874835232322713f23d2f10c083ae6fa893868b.tar.xz
net/textproto, sync: unlock mutexes appropriately before panics
Ensure mutexes are unlocked right before panics, where defers aren’t easily usable. Change-Id: I67c9870e7a626f590a8de8df6c8341c5483918dc GitHub-Last-Rev: bb8ffe538b3956892b55884fd64eadfce326f7b0 GitHub-Pull-Request: golang/go#37143 Reviewed-on: https://go-review.googlesource.com/c/go/+/218717 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/net/textproto/pipeline.go1
-rw-r--r--src/sync/rwmutex_test.go2
2 files changed, 3 insertions, 0 deletions
diff --git a/src/net/textproto/pipeline.go b/src/net/textproto/pipeline.go
index e2d9af34c5..1928a306bf 100644
--- a/src/net/textproto/pipeline.go
+++ b/src/net/textproto/pipeline.go
@@ -99,6 +99,7 @@ func (s *sequencer) Start(id uint) {
func (s *sequencer) End(id uint) {
s.mu.Lock()
if s.id != id {
+ s.mu.Unlock()
panic("out of sync")
}
id++
diff --git a/src/sync/rwmutex_test.go b/src/sync/rwmutex_test.go
index 9ee8864ceb..c98e69fd07 100644
--- a/src/sync/rwmutex_test.go
+++ b/src/sync/rwmutex_test.go
@@ -59,6 +59,7 @@ func reader(rwm *RWMutex, num_iterations int, activity *int32, cdone chan bool)
rwm.RLock()
n := atomic.AddInt32(activity, 1)
if n < 1 || n >= 10000 {
+ rwm.RUnlock()
panic(fmt.Sprintf("wlock(%d)\n", n))
}
for i := 0; i < 100; i++ {
@@ -74,6 +75,7 @@ func writer(rwm *RWMutex, num_iterations int, activity *int32, cdone chan bool)
rwm.Lock()
n := atomic.AddInt32(activity, 10000)
if n != 10000 {
+ rwm.Unlock()
panic(fmt.Sprintf("wlock(%d)\n", n))
}
for i := 0; i < 100; i++ {