]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid reference to stale stack after GC shrinkstack
authorRuss Cox <rsc@golang.org>
Thu, 30 Jul 2015 23:39:16 +0000 (19:39 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 31 Jul 2015 02:18:42 +0000 (02:18 +0000)
Dangling pointer error. Unlikely to trigger in practice, but still.
Found by running GODEBUG=efence=1 GOGC=1 trace.test.

Change-Id: Ice474dedcf62dd33ab77526287a023ba3b166db9
Reviewed-on: https://go-review.googlesource.com/12991
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mgc.go

index 614860e7114aa51301c01e6914e90f6acac1460e..f0e05f61aaa6df8f1362162ff084890b4a766af7 100644 (file)
@@ -1064,6 +1064,16 @@ func gc(mode int) {
        // need to switch to g0 so we can shrink the stack.
        systemstack(func() {
                gcMark(startTime)
+               // Must return immediately.
+               // The outer function's stack may have moved
+               // during gcMark (it shrinks stacks, including the
+               // outer function's stack), so we must not refer
+               // to any of its variables. Return back to the
+               // non-system stack to pick up the new addresses
+               // before continuing.
+       })
+
+       systemstack(func() {
                heap2 = work.bytesMarked
                if debug.gccheckmark > 0 {
                        // Run a full stop-the-world mark using checkmark bits,