Lock access to S.cache

This commit is contained in:
Özgür Kesim 2020-01-21 13:38:26 +01:00
parent 5b967134e8
commit d15586390a

View File

@ -335,9 +335,12 @@ func (S *Scanner) searchSymbolInPid(pid int) (offset uint64, found bool) {
func (S *Scanner) findSymbolInELF(pathname string) (offset uint64, found bool) { func (S *Scanner) findSymbolInELF(pathname string) (offset uint64, found bool) {
// 0. Return the value from the cache, if found. // 0. Return the value from the cache, if found.
S.RLock()
if offset, found = S.cache[pathname]; found { if offset, found = S.cache[pathname]; found {
S.RUnlock()
return offset, found return offset, found
} }
S.RUnlock()
// 1. Open the file with the ELF-parser // 1. Open the file with the ELF-parser
file, err := elf.Open(pathname) file, err := elf.Open(pathname)
@ -390,7 +393,9 @@ func (S *Scanner) findSymbolInELF(pathname string) (offset uint64, found bool) {
// 6. Store this calculation in our cache so that we don't to touch // 6. Store this calculation in our cache so that we don't to touch
// this file again. // this file again.
S.Lock()
S.cache[pathname] = vmOffset S.cache[pathname] = vmOffset
S.Unlock()
return vmOffset, true return vmOffset, true
} }