]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mount: fix loopdev deinitialization
authorKarel Zak <kzak@redhat.com>
Fri, 30 Sep 2011 09:05:37 +0000 (11:05 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 30 Sep 2011 09:05:37 +0000 (11:05 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
mount/mount.c

index 4f6a1637a06b6819422b8f2a7b7b31772f6d4a2a..f8ea5ca1f7859d52411177d0fac835da7a2df1e5 100644 (file)
@@ -1294,6 +1294,7 @@ loop_check(const char **spec, const char **type, int *flags,
 
        if (!*loopdev) {
          error(_("mount: failed to found free loop device"));
+         loopcxt_deinit(&lc);
          goto err;     /* no more loop devices */
        }
        if (verbose)
@@ -1307,8 +1308,10 @@ loop_check(const char **spec, const char **type, int *flags,
          rc = loopcxt_set_sizelimit(&lc, sizelimit);
        if (!rc)
          loopcxt_set_flags(&lc, loop_opts);
+
        if (rc) {
           error(_("mount: %s: failed to set loopdev attributes"), *loopdev);
+          loopcxt_deinit(&lc);
           goto err;
        }
 
@@ -1324,6 +1327,7 @@ loop_check(const char **spec, const char **type, int *flags,
            my_free(*loopdev);
            *loopdev = NULL;
          }
+         loopcxt_deinit(&lc);
          goto err;
        }
 
@@ -1335,6 +1339,7 @@ loop_check(const char **spec, const char **type, int *flags,
            continue;
        }
        error(_("mount: stolen loop=%s"), *loopdev);
+       loopcxt_deinit(&lc);
        goto err;
 
       } while (!*loopdev);
@@ -1349,18 +1354,16 @@ loop_check(const char **spec, const char **type, int *flags,
       if (loopcxt_is_autoclear(&lc))
         /* Prevent recording loop dev in mtab for cleanup on umount */
         *loop = 0;
+
+      /* We have to keep the device open until mount(2), otherwise it will
+       * be auto-cleared by kernel (because LO_FLAGS_AUTOCLEAR) */
+      loopcxt_set_fd(&lc, -1, 0);
+      loopcxt_deinit(&lc);
     }
   }
 
-  /* We have to keep the device open until mount(2), otherwise it will
-   * be auto-cleared by kernel (because LO_FLAGS_AUTOCLEAR) */
-  loopcxt_set_fd(&lc, -1, 0);
-
-  loopcxt_deinit(&lc);
   return 0;
-
 err:
-  loopcxt_deinit(&lc);
   return EX_FAIL;
 }