Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commit03290b5

Browse files
committed
[release-branch.go1.1] runtime: fix GC scanning of slices
««« CL9372044 / 1abed5873071runtime: fix GC scanning of slicesIf a slice points to an array embedded in a struct,the whole struct can be incorrectly scanned as the slice buffer.Fixes#5443.R=cshapiro, iant, r, cshapiro, minux.maCC=bradfitz, gobot, golang-devhttps://golang.org/cl/9372044»»»R=cshapiro, iantCC=golang-devhttps://golang.org/cl/10027043
1 parent5f1cf34 commit03290b5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎src/pkg/runtime/gc_test.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,27 @@ func TestGcHashmapIndirection(t *testing.T) {
9797
m[a]=T{}
9898
}
9999
}
100+
101+
funcTestGcArraySlice(t*testing.T) {
102+
typeXstruct {
103+
buf [1]byte
104+
nextbuf []byte
105+
next*X
106+
}
107+
varhead*X
108+
fori:=0;i<10;i++ {
109+
p:=&X{}
110+
p.buf[0]=42
111+
p.next=head
112+
ifhead!=nil {
113+
p.nextbuf=head.buf[:]
114+
}
115+
head=p
116+
runtime.GC()
117+
}
118+
forp:=head;p!=nil;p=p.next {
119+
ifp.buf[0]!=42 {
120+
t.Fatal("corrupted heap")
121+
}
122+
}
123+
}

‎src/pkg/runtime/mgc0.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,11 @@ scanblock(Workbuf *wbuf, Obj *wp, uintptr nobj, bool keepworking)
799799
sliceptr= (Slice*)(stack_top.b+pc[1]);
800800
if(sliceptr->cap!=0) {
801801
obj=sliceptr->array;
802-
objti=pc[2] |PRECISE |LOOP;
802+
// Can't use slice element type for scanning,
803+
// because if it points to an array embedded
804+
// in the beginning of a struct,
805+
// we will scan the whole struct as the slice.
806+
// So just obtain type info from heap.
803807
}
804808
pc+=3;
805809
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp