summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-09-17 13:25:46 -0700
committerKeith Randall <khr@golang.org>2014-09-17 13:25:46 -0700
commitf8b9e9ed43d8e43b964f328148cf29b4a9e2e85f (patch)
tree87e91d2d0b4c8721ab4f5d1759244b5345e4139e
parent022dacba94475cb76d850c8cfd61b38ce7e0cc8f (diff)
downloadgo-f8b9e9ed43d8e43b964f328148cf29b4a9e2e85f.tar.gz
runtime: free stacks of Gdead goroutines at GC time
We could probably free the G structures as well, but for the allg list. Leaving that for another day. Fixes issue 8287 LGTM=rsc R=golang-codereviews, dvyukov, khr, rsc CC=golang-codereviews https://codereview.appspot.com/145010043
-rw-r--r--src/runtime/stack.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/runtime/stack.c b/src/runtime/stack.c
index b38ee31d4..95a5a123d 100644
--- a/src/runtime/stack.c
+++ b/src/runtime/stack.c
@@ -806,8 +806,16 @@ runtime·shrinkstack(G *gp)
{
uintptr used, oldsize, newsize;
- if(runtime·readgstatus(gp) == Gdead)
+ if(runtime·readgstatus(gp) == Gdead) {
+ if(gp->stack.lo != 0) {
+ // Free whole stack - it will get reallocated
+ // if G is used again.
+ runtime·stackfree(gp->stack);
+ gp->stack.lo = 0;
+ gp->stack.hi = 0;
+ }
return;
+ }
if(gp->stack.lo == 0)
runtime·throw("missing stack in shrinkstack");