Merge pull request #5026 from lifubang/ci-detect-fdleak-try-best

fix fd leaks and detect them as comprehensively as possible
This commit is contained in:
Akihiro Suda
2025-11-26 08:33:53 +09:00
committed by GitHub
14 changed files with 222 additions and 64 deletions
+8 -6
View File
@@ -589,6 +589,12 @@ func (m *mountEntry) createOpenMountpoint(rootfs string) (Err error) {
func mountToRootfs(c *mountConfig, m mountEntry) error {
rootfs := c.root
defer func() {
if m.dstFile != nil {
_ = m.dstFile.Close()
m.dstFile = nil
}
}()
// procfs and sysfs are special because we need to ensure they are actually
// mounted on a specific path in a container without any funny business.
@@ -629,12 +635,6 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
if err := m.createOpenMountpoint(rootfs); err != nil {
return fmt.Errorf("create mountpoint for %s mount: %w", m.Destination, err)
}
defer func() {
if m.dstFile != nil {
_ = m.dstFile.Close()
m.dstFile = nil
}
}()
switch m.Device {
case "mqueue":
@@ -995,6 +995,8 @@ func createDeviceNode(rootfs string, node *devices.Device, bind bool) error {
if err != nil {
return fmt.Errorf("mkdir parent of device inode %q: %w", node.Path, err)
}
defer destDir.Close()
if bind {
return bindMountDeviceNode(destDir, destName, node)
}