Browse Source

runtime: fix a heap corruption where some blocks were not marked as reachable

This is a rather critical error and I wonder why it hasn't been
discovered earlier.
pull/419/head
Ayke van Laethem 5 years ago
committed by Ron Evans
parent
commit
ed7c242a09
  1. 7
      src/runtime/gc_marksweep.go

7
src/runtime/gc_marksweep.go

@ -119,7 +119,7 @@ func (b gcBlock) findHead() gcBlock {
// findNext returns the first block just past the end of the tail. This may or // findNext returns the first block just past the end of the tail. This may or
// may not be the head of an object. // may not be the head of an object.
func (b gcBlock) findNext() gcBlock { func (b gcBlock) findNext() gcBlock {
if b.state() == blockStateHead { if b.state() == blockStateHead || b.state() == blockStateMark {
b++ b++
} }
for b.state() == blockStateTail { for b.state() == blockStateTail {
@ -303,6 +303,11 @@ func markRoots(start, end uintptr) {
if gcDebug { if gcDebug {
println("mark from", start, "to", end, int(end-start)) println("mark from", start, "to", end, int(end-start))
} }
if gcAsserts {
if start >= end {
runtimePanic("gc: unexpected range to mark")
}
}
for addr := start; addr != end; addr += unsafe.Sizeof(addr) { for addr := start; addr != end; addr += unsafe.Sizeof(addr) {
root := *(*uintptr)(unsafe.Pointer(addr)) root := *(*uintptr)(unsafe.Pointer(addr))

Loading…
Cancel
Save