diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-01-18 10:54:27 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-01-18 12:27:29 -0500 |
commit | abbb00766a8d10f63bbafb60bb13eb4672d7f44a (patch) | |
tree | 9586536fb2988cadf8275c3b8539c1a36f9d5ba8 /dir.c | |
parent | fec892981ff8631ee380761c4b9ee640c9e93509 (diff) | |
download | bfs-abbb00766a8d10f63bbafb60bb13eb4672d7f44a.tar.xz |
dir: Fix extra close() if fdopendir() fails
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1,6 +1,6 @@ /**************************************************************************** * bfs * - * Copyright (C) 2021 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2021-2022 Tavian Barnes <tavianator@tavianator.com> * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -139,7 +139,9 @@ struct bfs_dir *bfs_opendir(int at_fd, const char *at_path) { dir->dir = fdopendir(fd); if (!dir->dir) { int error = errno; - close(fd); + if (at_path) { + close(fd); + } free(dir); errno = error; return NULL; |