From 45223fd3c5a13da9209c4f44d7593cb42cab94fb Mon Sep 17 00:00:00 2001 From: Maurizio Lombardi Date: Tue, 14 Dec 2021 10:09:42 +0100 Subject: [PATCH 3/6] nvme: do not leak an open file handle We performed a "sec_fd=open(cfg.file)" earlier, so we should not overwrite the handle. Signed-off-by: Maurizio Lombardi --- nvme.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/nvme.c b/nvme.c index 862f9b6..5beeac7 100644 --- a/nvme.c +++ b/nvme.c @@ -4379,17 +4379,10 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p fprintf(stderr, "WARNING: --tl not dword aligned; unaligned bytes may be truncated\n"); if (strlen(cfg.file) == 0) { + close(sec_fd); sec_fd = STDIN_FILENO; sec_size = cfg.tl; } else { - sec_fd = open(cfg.file, O_RDONLY); - if (sec_fd < 0) { - fprintf(stderr, "Failed to open %s: %s\n", - cfg.file, strerror(errno)); - err = -EINVAL; - goto close_fd; - } - err = fstat(sec_fd, &sb); if (err < 0) { perror("fstat"); -- 2.27.0