From 69785c117c0edd3d8a7fc94a5241d27d3c74c1e1 Mon Sep 17 00:00:00 2001 From: lifubang Date: Tue, 18 Nov 2025 10:15:29 +0000 Subject: [PATCH] libct: always close m.dstFile in mountToRootfs Signed-off-by: lifubang --- libcontainer/rootfs_linux.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index 94b664eeb..5128159bc 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -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":