]> Cypherpunks repositories - gostls13.git/commitdiff
net/textproto, sync: unlock mutexes appropriately before panics
authorBurtonQin <bobbqqin@gmail.com>
Wed, 8 Apr 2020 16:03:18 +0000 (16:03 +0000)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Wed, 8 Apr 2020 16:19:51 +0000 (16:19 +0000)
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>

src/net/textproto/pipeline.go
src/sync/rwmutex_test.go

index e2d9af34c5718b53f21e47ee51606078d356da79..1928a306bf7ef52e21457aafd9958f4086e2de7c 100644 (file)
@@ -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++
index 9ee8864cebb8eb36c35c389677a06c39d75f4761..c98e69fd07d7457b55a2fcfb9c5c875a8a8af05e 100644 (file)
@@ -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++ {