From: Jan Ziak <0xe2.0x9a.0x9b@gmail.com> Date: Thu, 27 Dec 2012 18:35:04 +0000 (+0800) Subject: reflect: declare slice as *[]unsafe.Pointer instead of *[]byte X-Git-Tag: go1.1rc2~1526 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=90f9beca15c951ef2cefa9942f87b71ae125ccd2;p=gostls13.git 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 --- diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index 93401fea52..10a4c0775b 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -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))