Skip to content

Commit a3118aa

Browse files
authored
Prevent finalization of pfelf files while using their data. (#877)
1 parent e7c2162 commit a3118aa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libpf/pfelf/file.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"hash/crc32"
2929
"io"
3030
"path/filepath"
31+
"runtime"
3132
"runtime/debug"
3233
"slices"
3334
"syscall"
@@ -581,7 +582,7 @@ func (f *File) GetBuildID() (string, error) {
581582
if err != nil {
582583
return "", err
583584
}
584-
585+
runtime.KeepAlive(f)
585586
return getBuildIDFromNotes(data)
586587
}
587588

@@ -726,6 +727,7 @@ func (f *File) visitTLSDescriptorsForSection(visitor func(ElfReloc, string) bool
726727
return false, nil
727728
}
728729
}
730+
runtime.KeepAlive(f)
729731

730732
return true, nil
731733
}
@@ -742,6 +744,7 @@ func (f *File) GetDebugLink() (linkName string, crc int32, err error) {
742744
if err != nil {
743745
return "", 0, fmt.Errorf("could not read link: %w", ErrNoDebugLink)
744746
}
747+
runtime.KeepAlive(f)
745748
return ParseDebugLink(d)
746749
}
747750

@@ -1103,6 +1106,7 @@ func (f *File) visitSymbolTable(name string, visitor func(libpf.Symbol) bool) er
11031106
}
11041107
}
11051108
}
1109+
runtime.KeepAlive(f)
11061110
return nil
11071111
}
11081112

0 commit comments

Comments
 (0)