aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2023-11-15 21:54:45 +0000
committerMichael Knyszek <mknyszek@google.com>2023-11-16 05:48:17 +0000
commit17eb0a2bac79eda8dc71d628474989d05d9755c5 (patch)
tree12138930b91eb1100ec6075b4f5dd340d17a0f89 /src
parent0011342590391655bd0cd732cf89c385c30c1278 (diff)
downloadgo-17eb0a2bac79eda8dc71d628474989d05d9755c5.tar.xz
runtime: fix liveness issue in test-only getgcmask
getgcmask stops referencing the object passed to it sometime between when the object is looked up and when the function returns. Notably, this can happen while the GC mask is actively being produced, and thus the GC might free the object. This is easily reproducible by adding a runtime.GC call at just the right place. Adding a KeepAlive on the heap-object path fixes it. Fixes #64188. Change-Id: I5ed4cae862fc780338b60d969fd7fbe896352ce4 Reviewed-on: https://go-review.googlesource.com/c/go/+/542716 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/mbitmap_allocheaders.go5
-rw-r--r--src/runtime/mbitmap_noallocheaders.go5
2 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime/mbitmap_allocheaders.go b/src/runtime/mbitmap_allocheaders.go
index 77f5b4c990..319d71f92f 100644
--- a/src/runtime/mbitmap_allocheaders.go
+++ b/src/runtime/mbitmap_allocheaders.go
@@ -1078,6 +1078,11 @@ func getgcmask(ep any) (mask []byte) {
for len(mask) > 0 && mask[len(mask)-1] == 0 {
mask = mask[:len(mask)-1]
}
+
+ // Make sure we keep ep alive. We may have stopped referencing
+ // ep's data pointer sometime before this point and it's possible
+ // for that memory to get freed.
+ KeepAlive(ep)
return
}
diff --git a/src/runtime/mbitmap_noallocheaders.go b/src/runtime/mbitmap_noallocheaders.go
index 96c70a0970..dab15889a4 100644
--- a/src/runtime/mbitmap_noallocheaders.go
+++ b/src/runtime/mbitmap_noallocheaders.go
@@ -744,6 +744,11 @@ func getgcmask(ep any) (mask []byte) {
for len(mask) > 0 && mask[len(mask)-1] == 0 {
mask = mask[:len(mask)-1]
}
+
+ // Make sure we keep ep alive. We may have stopped referencing
+ // ep's data pointer sometime before this point and it's possible
+ // for that memory to get freed.
+ KeepAlive(ep)
return
}