Skip to content

Commit 4874835

Browse files
Chain-Foxodeke-em
authored andcommitted
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: bb8ffe5 GitHub-Pull-Request: #37143 Reviewed-on: https://go-review.googlesource.com/c/go/+/218717 Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7a35d39 commit 4874835

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/net/textproto/pipeline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (s *sequencer) Start(id uint) {
9999
func (s *sequencer) End(id uint) {
100100
s.mu.Lock()
101101
if s.id != id {
102+
s.mu.Unlock()
102103
panic("out of sync")
103104
}
104105
id++

src/sync/rwmutex_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func reader(rwm *RWMutex, num_iterations int, activity *int32, cdone chan bool)
5959
rwm.RLock()
6060
n := atomic.AddInt32(activity, 1)
6161
if n < 1 || n >= 10000 {
62+
rwm.RUnlock()
6263
panic(fmt.Sprintf("wlock(%d)\n", n))
6364
}
6465
for i := 0; i < 100; i++ {
@@ -74,6 +75,7 @@ func writer(rwm *RWMutex, num_iterations int, activity *int32, cdone chan bool)
7475
rwm.Lock()
7576
n := atomic.AddInt32(activity, 10000)
7677
if n != 10000 {
78+
rwm.Unlock()
7779
panic(fmt.Sprintf("wlock(%d)\n", n))
7880
}
7981
for i := 0; i < 100; i++ {

0 commit comments

Comments
 (0)