]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Close file on error path. 744/head
authorKizuna-Meraki <z9@kizunameraki.de>
Thu, 17 Feb 2022 20:27:01 +0000 (21:27 +0100)
committerKizuna-Meraki <z9@kizunameraki.de>
Thu, 17 Feb 2022 20:27:01 +0000 (21:27 +0100)
The file was only be closed when there was no error and
was being left open when there was an error. By moving
the close(fd) statement out of the if-clause, the file
can be close regardless if there is an error or not.
After the file is closed, it can be checked for errors.

random_seed.c

index 462297959466f89e9bf7c7762222b63a6eef039f..7945824c7a9d78c4d4de5a72650d5d05551344f7 100644 (file)
@@ -237,13 +237,15 @@ static int get_dev_random_seed(int *seed)
        }
 
        ssize_t nread = read(fd, seed, sizeof(*seed));
+
+       close(fd);
+
        if (nread != sizeof(*seed))
        {
                fprintf(stderr, "error short read %s: %s", dev_random_file, strerror(errno));
                return -1;
        }
 
-       close(fd);
        return 0;
 }