From abbb00766a8d10f63bbafb60bb13eb4672d7f44a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 18 Jan 2022 10:54:27 -0500 Subject: dir: Fix extra close() if fdopendir() fails --- dir.c | 6 ++++-- 1 file 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 * + * Copyright (C) 2021-2022 Tavian Barnes * * * * 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; -- cgit v1.2.3