client: close dup'ed descriptor if fdopen() fails
authorJens Axboe <axboe@kernel.dk>
Fri, 15 Jun 2018 15:18:04 +0000 (09:18 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 15 Jun 2018 15:18:04 +0000 (09:18 -0600)
The saga continues... Ensure that we close the dup'ed descriptor,
if we give up due to fdopen() failure.

Reported-by: Bart Van Assche <bart.vanassche@wdc.com>
Fixes: ec9e13345f3f ("client: check return of dup(2)")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c

index 611ee2f5a3f929d9d7ae7c7d14c229196bdfedbb..2a86ea971bf7b871e08d469943eb18fce0a8c1d7 100644 (file)
--- 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;
 }