From af84cd66149507424814cf9c0b4950f4cf66e3b7 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 15 Jun 2018 09:18:04 -0600 Subject: [PATCH] client: close dup'ed descriptor if fdopen() fails The saga continues... Ensure that we close the dup'ed descriptor, if we give up due to fdopen() failure. Reported-by: Bart Van Assche Fixes: ec9e13345f3f ("client: check return of dup(2)") Signed-off-by: Jens Axboe --- client.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client.c b/client.c index 611ee2f5..2a86ea97 100644 --- a/client.c +++ b/client.c @@ -130,8 +130,11 @@ static int read_ini_data(int fd, void *data, size_t size) return errno; fp = fdopen(dupfd, "r"); - if (!fp) - return errno; + if (!fp) { + ret = errno; + close(dupfd); + goto out; + } while (1) { ssize_t len; @@ -163,6 +166,7 @@ static int read_ini_data(int fd, void *data, size_t size) } fclose(fp); +out: return ret; } -- 2.25.1