From 6a14329c6d24c7f29e525fcd1464d535c48b80d8 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Feb 2025 10:37:28 +0100 Subject: [PATCH] findmnt: fix resource leaks [coverity scan] Signed-off-by: Karel Zak --- misc-utils/findmnt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index a497ceeca..fbfb84c94 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -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; } /* -- 2.47.3