]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix possible mem leak in has_utab_entry() [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 10:03:49 +0000 (11:03 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 10:03:49 +0000 (11:03 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_umount.c

index c50b97bfbb8be8f76cd9b1d9684a9b6fac57837d..2a39a6f46d662e647cc0edb85653dc483eb1f568 100644 (file)
@@ -169,6 +169,7 @@ static int has_utab_entry(struct libmnt_context *cxt, const char *target)
        struct libmnt_fs *fs;
        struct libmnt_iter itr;
        char *cn = NULL;
+       int rc = 0;
 
        assert(cxt);
 
@@ -191,10 +192,16 @@ static int has_utab_entry(struct libmnt_context *cxt, const char *target)
        mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
 
        while (mnt_table_next_fs(cxt->utab, &itr, &fs) == 0) {
-               if (mnt_fs_streq_target(fs, cn))
-                       return 1;
+               if (mnt_fs_streq_target(fs, cn)) {
+                       rc = 1;
+                       break;
+               }
        }
-       return 0;
+
+       if (!cache)
+               free(cn);
+
+       return rc;
 }
 
 /* this is umount replacement to mnt_context_apply_fstab(), use