]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: fix resource leaks [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 18 Feb 2025 09:37:28 +0000 (10:37 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Feb 2025 09:37:28 +0000 (10:37 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/findmnt.c

index a497ceecab99d4a37bae48e3c6939e54712fd7ea..fbfb84c9443abe7db04568d81ab7eb4a7409f56c 100644 (file)
@@ -1087,31 +1087,33 @@ static struct libmnt_table *parse_tabfiles(char **files,
 
 static struct libmnt_table *fetch_listmount(void)
 {
-       struct libmnt_table *tb;
-       struct libmnt_statmnt *sm;
+       struct libmnt_table *tb = NULL;
+       struct libmnt_statmnt *sm = NULL;
 
        sm = mnt_new_statmnt();
        if (!sm) {
                warn(_("failed to allocate statmnt handler"));
-               return NULL;
+               goto failed;
        }
 
        tb = mnt_new_table();
        if (!tb) {
                warn(_("failed to initialize libmount table"));
-               return NULL;
+               goto failed;
        }
 
        mnt_table_refer_statmnt(tb, sm);
 
        if (mnt_table_fetch_listmount(tb) != 0) {
                warn(_("failed to fetch mount nodes"));
-               mnt_unref_table(tb);
-               mnt_unref_statmnt(sm);
-               return NULL;
+               goto failed;
        }
 
        return tb;
+failed:
+       mnt_unref_table(tb);
+       mnt_unref_statmnt(sm);
+       return NULL;
 }
 
 /*