summaryrefslogtreecommitdiff
path: root/src/runtime/select.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-03 15:33:29 -0400
committerRuss Cox <rsc@golang.org>2014-10-03 15:33:29 -0400
commita81469cf0b101e552d1968469f528456d9d7835a (patch)
treee29dfcb0543012d375fe28f4cff3f11ee1a395ec /src/runtime/select.go
parent4f87028de45e479d54ad7b18335abb4842e830ae (diff)
downloadgo-a81469cf0b101e552d1968469f528456d9d7835a.tar.gz
runtime: clear sg.selectdone before saving in SudoG cache
Removes another dangling pointer that might cause a memory leak in 1.4 or crash the GC in 1.5. LGTM=rlh R=golang-codereviews CC=golang-codereviews, iant, khr, r, rlh https://codereview.appspot.com/150520043
Diffstat (limited to 'src/runtime/select.go')
-rw-r--r--src/runtime/select.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/select.go b/src/runtime/select.go
index 1bcea8c4b..9de057b87 100644
--- a/src/runtime/select.go
+++ b/src/runtime/select.go
@@ -377,8 +377,14 @@ loop:
// iterating through the linked list they are in reverse order.
cas = nil
sglist = gp.waiting
- // Clear all elem before unlinking from gp.waiting.
+ // Clear all selectdone and elem before unlinking from gp.waiting.
+ // They must be cleared before being put back into the sudog cache.
+ // Clear before unlinking, because if a stack copy happens after the unlink,
+ // they will not be updated, they will be left pointing to the old stack,
+ // which creates dangling pointers, which may be detected by the
+ // garbage collector.
for sg1 := gp.waiting; sg1 != nil; sg1 = sg1.waitlink {
+ sg1.selectdone = nil
sg1.elem = nil
}
gp.waiting = nil