diff options
author | Andrej Krpic <ak77@tnode.com> | 2014-12-22 18:55:11 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-12-22 21:41:02 +0100 |
commit | bf0948ef5ee92ace7f8f46ab7cf71ddec09a90a1 (patch) | |
tree | e94a18bc2c89d1cf5ecb58e96b77c024a21fdb8f | |
parent | fd8e5e379c23c5fbcec3e76894b839233df09067 (diff) |
uhttpd: Fix possible memory leaks when generating directory listing
scandir() call requires free() of each returned dirent structure
and parent list. Code constructing HTML response of directory
listing is missing a call to free in some cases.
Signed-off-by: Andrej Krpic <ak77@tnode.com>
-rw-r--r-- | file.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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]); } } |