Commit ea875017 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: fix heap memory corruption

With concurrent sweeping finc if modified by runfinq and queuefinalizer concurrently.
Fixes crashes like this one:
http://build.golang.org/log/6ad7b59ef2e93e3c9347eabfb4c4bd66df58fd5a
Fixes #7324.
Update #7396

LGTM=rsc
R=golang-codereviews, minux.ma, rsc
CC=golang-codereviews, khr
https://golang.org/cl/67980043
parent 6e612ae0
...@@ -2551,7 +2551,7 @@ runfinq(void) ...@@ -2551,7 +2551,7 @@ runfinq(void)
if(framecap < framesz) { if(framecap < framesz) {
runtime·free(frame); runtime·free(frame);
// The frame does not contain pointers interesting for GC, // The frame does not contain pointers interesting for GC,
// all not yet finalized objects are stored in finc. // all not yet finalized objects are stored in finq.
// If we do not mark it as FlagNoScan, // If we do not mark it as FlagNoScan,
// the last finalized object is not collected. // the last finalized object is not collected.
frame = runtime·mallocgc(framesz, 0, FlagNoScan|FlagNoInvokeGC); frame = runtime·mallocgc(framesz, 0, FlagNoScan|FlagNoInvokeGC);
...@@ -2580,8 +2580,10 @@ runfinq(void) ...@@ -2580,8 +2580,10 @@ runfinq(void)
f->ot = nil; f->ot = nil;
} }
fb->cnt = 0; fb->cnt = 0;
runtime·lock(&gclock);
fb->next = finc; fb->next = finc;
finc = fb; finc = fb;
runtime·unlock(&gclock);
} }
runtime·gc(1); // trigger another gc to clean up the finalized objects, if possible runtime·gc(1); // trigger another gc to clean up the finalized objects, if possible
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment