Skip to content

Commit 0cd3acc

Browse files
paulcacheuxlmb
authored andcommitted
btf: fix data race in (*mutableTypes).copy
Move the creation of the mutableTypes copy under the read lock, so that the access to the len of the source types is protected when pre-allocating the maps. Signed-off-by: Paul Cacheux <[email protected]>
1 parent 1bcc12e commit 0cd3acc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: btf/btf.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ func (mt *mutableTypes) copy() *mutableTypes {
9999
return nil
100100
}
101101

102+
// Prevent concurrent modification of mt.copiedTypeIDs.
103+
mt.mu.RLock()
104+
defer mt.mu.RUnlock()
105+
102106
mtCopy := &mutableTypes{
103107
mt.imm,
104108
sync.RWMutex{},
105109
make(map[Type]Type, len(mt.copies)),
106110
make(map[Type]TypeID, len(mt.copiedTypeIDs)),
107111
}
108112

109-
// Prevent concurrent modification of mt.copiedTypeIDs.
110-
mt.mu.RLock()
111-
defer mt.mu.RUnlock()
112-
113113
copiesOfCopies := make(map[Type]Type, len(mt.copies))
114114
for orig, copy := range mt.copies {
115115
// NB: We make a copy of copy, not orig, so that changes to mutable types

0 commit comments

Comments
 (0)