From: Karel Zak Date: Wed, 4 Jan 2023 12:21:17 +0000 (+0100) Subject: libmount: (mount) consolidate sysapi FDs close [coverity scan] X-Git-Tag: v2.39-rc1~208 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b3aaf9daf6cf3a63b26a35fb54642be6be90964f;p=thirdparty%2Futil-linux.git libmount: (mount) consolidate sysapi FDs close [coverity scan] Signed-off-by: Karel Zak --- diff --git a/libmount/src/hook_mount.c b/libmount/src/hook_mount.c index 1fd31d9473..6f3dfca0bc 100644 --- a/libmount/src/hook_mount.c +++ b/libmount/src/hook_mount.c @@ -50,6 +50,16 @@ #define get_sysapi(_cxt) mnt_context_get_sysapi(_cxt) +static void close_sysapi_fds(struct libmnt_sysapi *api) +{ + if (api->fd_fs >= 0) + close(api->fd_fs); + if (api->fd_tree >= 0) + close(api->fd_tree); + + api->fd_tree = api->fd_fs = -1; +} + /* * This hookset uses 'struct libmnt_sysapi' (mountP.h) as hookset data. */ @@ -61,10 +71,7 @@ static void free_hookset_data( struct libmnt_context *cxt, if (!api) return; - if (api->fd_fs >= 0) - close(api->fd_fs); - if (api->fd_tree >= 0) - close(api->fd_tree); + close_sysapi_fds(api); free(api); mnt_context_set_hookset_data(cxt, hs, NULL); @@ -242,12 +249,9 @@ static int hook_create_mount(struct libmnt_context *cxt, rc = -errno; } - if (rc) { + if (rc) /* cleanup after fail (libmount may only try the FS type) */ - close(api->fd_tree); - close(api->fd_fs); - api->fd_tree = api->fd_fs = -1; - } + close_sysapi_fds(api); if (!rc && cxt->fs) { struct statx st;