From 319d21e66244bb0ed766f26b57e188e34b541335 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 23 Aug 2019 18:08:56 +0200 Subject: [PATCH] runtime: don't mark the object right before a non-existing object False positives (pointers that point to nowhere but happen to point into the heap) would result in the block just before that pointer to be marked. This is clearly not intended, so ignore such a pointer. --- src/runtime/gc_conservative.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/runtime/gc_conservative.go b/src/runtime/gc_conservative.go index 24e13df96..cff9f4f7c 100644 --- a/src/runtime/gc_conservative.go +++ b/src/runtime/gc_conservative.go @@ -327,6 +327,12 @@ func markRoots(start, end uintptr) { func markRoot(addr, root uintptr) { if looksLikePointer(root) { block := blockFromAddr(root) + if block.state() == blockStateFree { + // The to-be-marked object doesn't actually exist. + // This could either be a dangling pointer (oops!) but most likely + // just a false positive. + return + } head := block.findHead() if head.state() != blockStateMark { if gcDebug {