mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: hashmap: move overflow pointer to end of bucket
Pointers to zero-sized values may end up pointing to the next object in memory, and possibly off the end of a span. This can cause memory leaks and/or confuse the garbage collector. By putting the overflow pointer at the end of the bucket, we make sure that pointers to any zero-sized keys or values don't accidentally point to the next object in memory. fixes #9384 Change-Id: I5d434df176984cb0210b4d0195dd106d6eb28f73 Reviewed-on: https://go-review.googlesource.com/1869 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
aaa4bf3720
commit
fbc56cf050
5 changed files with 57 additions and 42 deletions
|
|
@ -1646,10 +1646,6 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
|||
for i := 0; i < int(bucketSize*unsafe.Sizeof(uint8(0))/ptrsize); i++ {
|
||||
gc.append(bitsScalar)
|
||||
}
|
||||
gc.append(bitsPointer) // overflow
|
||||
if runtime.GOARCH == "amd64p32" {
|
||||
gc.append(bitsScalar)
|
||||
}
|
||||
// keys
|
||||
for i := 0; i < bucketSize; i++ {
|
||||
gc.appendProg(ktyp)
|
||||
|
|
@ -1658,6 +1654,11 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
|||
for i := 0; i < bucketSize; i++ {
|
||||
gc.appendProg(etyp)
|
||||
}
|
||||
// overflow
|
||||
gc.append(bitsPointer)
|
||||
if runtime.GOARCH == "amd64p32" {
|
||||
gc.append(bitsScalar)
|
||||
}
|
||||
|
||||
b := new(rtype)
|
||||
b.size = gc.size
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue