aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-07 12:36:27 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-07 12:36:27 +0100
commitf33e1c90535c9abae0d7c3e29cdb29ba94fb96cd (patch)
tree2c19bed8760d89a9849698091beb898f3e487d19
parent61dc4f42b346931b5a67da4f46013fd5e2fb6ad3 (diff)
downloadslcl-f33e1c90535c9abae0d7c3e29cdb29ba94fb96cd.tar.gz
cftw.c: Add missing call to closedir(2)
-rw-r--r--cftw.c18
1 files 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;
}