1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:08:37 -07:00

reflect: declare slice as *[]unsafe.Pointer instead of *[]byte

The new garbage collector (CL 6114046) may find the fake *[]byte value
and interpret its contents as bytes rather than as potential pointers.
This may lead the garbage collector to free memory blocks that
shouldn't be freed.

R=dvyukov, rsc, dave, minux.ma, remyoudompheng, iant
CC=golang-dev
https://golang.org/cl/7000059
This commit is contained in:
Jan Ziak 2012-12-28 02:35:04 +08:00 committed by Shenghou Ma
parent 5bcb9707b6
commit 90f9beca15

View File

@ -1491,7 +1491,7 @@ func (v Value) Slice(beg, end int) Value {
}
// Declare slice so that gc can see the base pointer in it.
var x []byte
var x []unsafe.Pointer
// Reinterpret as *SliceHeader to edit.
s := (*SliceHeader)(unsafe.Pointer(&x))
@ -1899,7 +1899,7 @@ func MakeSlice(typ Type, len, cap int) Value {
}
// Declare slice so that gc can see the base pointer in it.
var x []byte
var x []unsafe.Pointer
// Reinterpret as *SliceHeader to edit.
s := (*SliceHeader)(unsafe.Pointer(&x))