From f33e1c90535c9abae0d7c3e29cdb29ba94fb96cd Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 7 Mar 2023 12:36:27 +0100 Subject: cftw.c: Add missing call to closedir(2) --- cftw.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cftw.c b/cftw.c index 921a12e..bb05843 100644 --- a/cftw.c +++ b/cftw.c @@ -10,13 +10,14 @@ int cftw(const char *const dirpath, int (*const fn)(const char *, const struct stat *, void *), void *const user) { + int ret = -1; DIR *const d = opendir(dirpath); struct dirent *de; if (!d) { fprintf(stderr, "%s: opendir(2): %s\n", __func__, strerror(errno)); - return -1; + goto end; } while ((de = readdir(d))) @@ -38,7 +39,6 @@ int cftw(const char *const dirpath, int (*const fn)(const char *, } const int r = stat(d.str, &sb); - int ret = -1; if (r) fprintf(stderr, "%s: stat(2) %s: %s\n", @@ -54,8 +54,18 @@ int cftw(const char *const dirpath, int (*const fn)(const char *, dynstr_free(&d); if (ret) - return ret; + goto end; } - return 0; + ret = 0; + +end: + + if (d && closedir(d)) + { + fprintf(stderr, "%s: closedir(2): %s\n", __func__, strerror(errno)); + ret = -1; + } + + return ret; } -- cgit v1.2.3