Skip to content

Commit 92eb1e1

Browse files
committed
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 #8287 LGTM=rsc R=golang-codereviews, dvyukov, khr, rsc CC=golang-codereviews https://golang.org/cl/145010043
1 parent 6fb9d50 commit 92eb1e1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/runtime/stack.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,16 @@ runtime·shrinkstack(G *gp)
806806
{
807807
uintptr used, oldsize, newsize;
808808

809-
if(runtime·readgstatus(gp) == Gdead)
809+
if(runtime·readgstatus(gp) == Gdead) {
810+
if(gp->stack.lo != 0) {
811+
// Free whole stack - it will get reallocated
812+
// if G is used again.
813+
runtime·stackfree(gp->stack);
814+
gp->stack.lo = 0;
815+
gp->stack.hi = 0;
816+
}
810817
return;
818+
}
811819
if(gp->stack.lo == 0)
812820
runtime·throw("missing stack in shrinkstack");
813821

0 commit comments

Comments
 (0)