pkg/internal/filesystem/lock.go: potential nil pointer panic from file.Close() in deferred function #4802
-
|
Hi everyone, I was reading the nerdctl codebase to understand how networking is handled with containerd. Inside This is an edge case, but it can be resolved by simply removing the I can open a PR if that would be helpful. Here is a snippet of the function I am referring to: func commonlock(path string, mode lockType) (file *os.File, err error) {
defer func() {
if err != nil {
err = errors.Join(ErrLockFail, err, file.Close())
}
}()
if runtime.GOOS == "windows" {
if sl, err := os.Stat(path); err == nil && sl.IsDir() {
path = path + ".nerdctl.lock"
}
}
file, err = os.Open(path)
if errors.Is(err, os.ErrNotExist) {
file, err = os.OpenFile(path, os.O_RDONLY|os.O_CREATE, privateFilePermission)
}
if err != nil {
return nil, err
}
if err = platformSpecificLock(file, mode); err != nil {
return nil, errors.Join(err, file.Close())
}
return file, nil
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for reporting, could you open a PR? |
Beta Was this translation helpful? Give feedback.
Fixed in: