From 3f9f913f5302b71ef57467798f62dd3e83b217bc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 30 Jan 2016 13:58:35 -0500 Subject: bftw: Fix fd leak if fdopendir() fails. --- bftw.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } /** -- cgit v1.2.3