uhttpd: Fix possible memory leaks when generating directory listing
[project/uhttpd.git] / file.c
diff --git a/file.c b/file.c
index 055035eb7f715cd636918c2be75738c8338cb818..60dfdfa96705100029ea75a04eb537ac6f70229d 100644 (file)
--- a/file.c
+++ b/file.c
@@ -479,11 +479,11 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                bool dir = !!(files[i]->d_type & DT_DIR);
 
                if (name[0] == '.' && name[1] == 0)
-                       continue;
+                       goto next;
 
                sprintf(file, "%s", name);
                if (stat(local_path, &s))
-                       continue;
+                       goto next;
 
                if (!dir) {
                        suffix = "";
@@ -492,7 +492,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                }
 
                if (!(s.st_mode & mode))
-                       continue;
+                       goto next;
 
                uh_chunk_printf(cl,
                                "<li><strong><a href='%s%s%s'>%s</a>%s"
@@ -505,6 +505,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                                type, s.st_size / 1024.0);
 
                *file = 0;
+next:
                free(files[i]);
        }
 }
@@ -567,7 +568,6 @@ static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
                !uh_file_if_range(cl, &pi->stat) ||
                !uh_file_if_unmodified_since(cl, &pi->stat) ||
                !uh_file_if_none_match(cl, &pi->stat)) {
-               ustream_printf(cl->us, "Content-Length: 0\r\n");
                ustream_printf(cl->us, "\r\n");
                uh_request_done(cl);
                close(fd);