Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libpf/pfelf/file.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to place runtime.KeepAlive in the selected public API functions but leave other functions of *File without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were the only functions I happened to notice where we are getting a pointer to mmap'ed space, then possibly dropping the file (causing an munmap), then trying to access the mmap'ed pointer.

Is there another such function I missed?

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"hash/crc32"
"io"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"syscall"
Expand Down Expand Up @@ -580,7 +581,7 @@ func (f *File) GetBuildID() (string, error) {
if err != nil {
return "", err
}

runtime.KeepAlive(f)
return getBuildIDFromNotes(data)
}

Expand Down Expand Up @@ -716,6 +717,7 @@ func (f *File) insertTLSDescriptorsForSection(descs map[string]libpf.Address,

descs[symStr] = libpf.Address(rela.Off)
}
runtime.KeepAlive(f)

return nil
}
Expand All @@ -732,6 +734,7 @@ func (f *File) GetDebugLink() (linkName string, crc int32, err error) {
if err != nil {
return "", 0, fmt.Errorf("could not read link: %w", ErrNoDebugLink)
}
runtime.KeepAlive(f)
return ParseDebugLink(d)
}

Expand Down Expand Up @@ -1090,6 +1093,7 @@ func (f *File) visitSymbolTable(name string, visitor func(libpf.Symbol)) error {
})
}
}
runtime.KeepAlive(f)
return nil
}

Expand Down