Skip to content

Commit 98dc593

Browse files
committed
libct: always close m.dstFile in mountToRootfs
Signed-off-by: lifubang <lifubang@acmcoder.com> (cherry picked from commit e027288) Signed-off-by: lifubang <lifubang@acmcoder.com>
1 parent 167fa3f commit 98dc593

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libcontainer/rootfs_linux.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ func (m *mountEntry) createOpenMountpoint(rootfs string) (Err error) {
588588

589589
func mountToRootfs(c *mountConfig, m mountEntry) error {
590590
rootfs := c.root
591+
defer func() {
592+
if m.dstFile != nil {
593+
_ = m.dstFile.Close()
594+
m.dstFile = nil
595+
}
596+
}()
591597

592598
// procfs and sysfs are special because we need to ensure they are actually
593599
// mounted on a specific path in a container without any funny business.
@@ -628,12 +634,6 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
628634
if err := m.createOpenMountpoint(rootfs); err != nil {
629635
return fmt.Errorf("create mountpoint for %s mount: %w", m.Destination, err)
630636
}
631-
defer func() {
632-
if m.dstFile != nil {
633-
_ = m.dstFile.Close()
634-
m.dstFile = nil
635-
}
636-
}()
637637

638638
switch m.Device {
639639
case "mqueue":

0 commit comments

Comments
 (0)