Skip to content

Commit 3de0bd4

Browse files
committed
btf: make stringTable.LookupCached concurrency safe
stringTable has to be safe for concurrent use since it is shared between multiple decoders. Document this and add a lock to LookupCached to make it safe. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent 22ffff5 commit 3de0bd4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

btf/strings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ import (
77
"io"
88
"maps"
99
"strings"
10+
"sync"
1011
)
1112

13+
// stringTable is contains a sequence of null-terminated strings.
14+
//
15+
// It is safe for concurrent use.
1216
type stringTable struct {
1317
base *stringTable
1418
bytes []byte
1519

20+
mu sync.Mutex
1621
cache map[uint32]string
1722
}
1823

@@ -98,6 +103,9 @@ func (cst *stringTable) LookupCached(offset uint32) (string, error) {
98103
return "", nil
99104
}
100105

106+
cst.mu.Lock()
107+
defer cst.mu.Unlock()
108+
101109
if str, ok := cst.cache[offset]; ok {
102110
return str, nil
103111
}

0 commit comments

Comments
 (0)