commit 70d5d67d68410c852d9663a6e4935e508897ffdf
parent 9526d3d35917770ca5a021d745bcf50d382875b2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 8 Mar 2023 20:55:16 +0100
handledir: fix memory leak if writing a directory entry failed
Signed-off-by: Christoph Lohmann <20h@r-36.net>
Diffstat:
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/handlr.c b/handlr.c
@@ -67,10 +67,8 @@ handledir(int sock, char *path, char *port, char *base, char *args,
return;
} else {
for (i = 0; i < ndir && ret >= 0; i++) {
- if (dirent[i]->d_name[0] == '.') {
- free(dirent[i]);
+ if (dirent[i]->d_name[0] == '.')
continue;
- }
type = gettype(dirent[i]->d_name);
file = smprintf("%s%s%s", pa,
@@ -87,8 +85,9 @@ handledir(int sock, char *path, char *port, char *base, char *args,
humantime(&(st.st_mtime)),
e, ohost, port);
free(file);
- free(dirent[i]);
}
+ for (i = 0; i < ndir; i++)
+ free(dirent[i]);
free(dirent);
}
dprintf(sock, ".\r\n");