summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-01-30 13:58:35 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-01-30 13:58:35 -0500
commit3f9f913f5302b71ef57467798f62dd3e83b217bc (patch)
treed3ec92315a41cca7d20938bccf53181d805f9f8d
parentda51ac27f1849ad94753277650435ae482a0423f (diff)
downloadbfs-3f9f913f5302b71ef57467798f62dd3e83b217bc.tar.xz
bftw: Fix fd leak if fdopendir() fails.
-rw-r--r--bftw.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/bftw.c b/bftw.c
index d489bc8..5630109 100644
--- a/bftw.c
+++ b/bftw.c
@@ -234,7 +234,11 @@ static DIR *opendirat(int fd, const char *name) {
return NULL;
}
- return fdopendir(dfd);
+ DIR *dir = fdopendir(dfd);
+ if (!dir) {
+ close(dfd);
+ }
+ return dir;
}
/**