]> git.feebdaed.xyz Git - 0xmirror/runc.git/commitdiff
libct: always close m.dstFile in mountToRootfs
authorlifubang <lifubang@acmcoder.com>
Tue, 18 Nov 2025 10:15:29 +0000 (10:15 +0000)
committerlfbzhm <lifubang@acmcoder.com>
Thu, 20 Nov 2025 11:43:22 +0000 (19:43 +0800)
Signed-off-by: lifubang <lifubang@acmcoder.com>
libcontainer/rootfs_linux.go

index 94b664eeb5acce04094030daa70d2afd1bc6c3a6..5128159bc6045ee80549f3c3e0dfa5a48d937cd1 100644 (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":