From 5da6353987ccf73c67e9e1c68faa66989b76a583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 19 May 2021 14:32:15 +0200 Subject: [PATCH] libzfs: run_process: don't leak fd on reopen failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: John Kennedy Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12082 --- lib/libzfs/libzfs_util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 0fffbaaf7..57498ca3c 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -849,8 +849,10 @@ libzfs_read_stdout_from_fd(int fd, char **lines[]) char **tmp_lines = NULL, **tmp; fp = fdopen(fd, "r"); - if (fp == NULL) + if (fp == NULL) { + close(fd); return (0); + } while (getline(&line, &len, fp) != -1) { tmp = realloc(tmp_lines, sizeof (*tmp_lines) * (lines_cnt + 1)); if (tmp == NULL) {