Conversions to llapi_root_path_open missed a few close() calls, leading
to fd leaks.
These should be obvious enough to regroup in a single commit.
Fixes:
7154244354e3 ("LU-16786 utils: Replace open call to WANT_FD")
Change-Id: I3af25ef2981367bfaea7f5280972f84bee09a5c2
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53736
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Stephane Thiell <sthiell@stanford.edu>
Reviewed-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
fa = malloc(offsetof(struct fid_array, fa_fids[nr + 1]));
if (!fa) {
+ rc = -errno ?: -ENOMEM;
fprintf(stderr, "%s rmfid: error allocating %zd bytes: %s\n",
progname, offsetof(struct fid_array, fa_fids[nr + 1]),
- strerror(errno));
- return -ENOMEM;
+ strerror(-rc));
+ goto out_close;
}
fa->fa_nr = 0;
fa = NULL;
}
+out_close:
close(rootfd);
return rc;
}
{
int mnt_fd, rc;
- /* this will return a cached FD if available, so only one open needed.
- * WANT_FD doesn't modify lustre_dir so casting away "const" is OK */
-
rc = llapi_root_path_open(lustre_dir, &mnt_fd);
if (rc)
goto out;
- /* "mnt_fd" is cached internally for reuse, no need to close it */
rc = llapi_open_by_fid_at(mnt_fd, fid, flags);
+ close(mnt_fd);
out:
return rc;
}
}
rc = llapi_rmfid_at(rootfd, fa);
+ close(rootfd);
if (rc < 0) {
fprintf(stderr, "lfs rmfid: cannot remove FIDs: %s\n",
strerror(-rc));