summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-01-18 10:54:27 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-01-18 12:27:29 -0500
commitabbb00766a8d10f63bbafb60bb13eb4672d7f44a (patch)
tree9586536fb2988cadf8275c3b8539c1a36f9d5ba8
parentfec892981ff8631ee380761c4b9ee640c9e93509 (diff)
downloadbfs-abbb00766a8d10f63bbafb60bb13eb4672d7f44a.tar.xz
dir: Fix extra close() if fdopendir() fails
-rw-r--r--dir.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index e0a7307..90c2e3e 100644
--- a/dir.c
+++ b/dir.c
@@ -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;