summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Vorburger <mike@vorburger.ch>2013-12-29 22:34:11 +0100
committerMichael Vorburger <mike@vorburger.ch>2013-12-29 22:34:11 +0100
commit5f210b5b2b0b150acf8f4b5890c9811cd65e2aa9 (patch)
treed1493a9a5802119dd97696ea4c7f6838edcdbd0f /src
parente50276645629cf81978853a326b5fc4a30fa0105 (diff)
Fix for segfault due to errononeous free() in case of scandir error ^Cailed to scan directory'
Diffstat (limited to 'src')
-rw-r--r--src/filelist.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/filelist.c b/src/filelist.c
index 8d19e41..e06c6de 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -263,27 +263,27 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level)
default:
weprintf("Failed to scan directory %s:", path);
}
- }
-
- for (cnt = 0; cnt < n; cnt++) {
- if (strcmp(de[cnt]->d_name, ".")
- && strcmp(de[cnt]->d_name, "..")) {
- char *newfile;
-
- newfile = estrjoin("", path, "/", de[cnt]->d_name, NULL);
-
- /* This ensures we go down one level even if not fully recursive
- - this way "feh some_dir" expands to some_dir's contents */
- if (opt.recursive)
- add_file_to_filelist_recursively(newfile, FILELIST_CONTINUE);
- else
- add_file_to_filelist_recursively(newfile, FILELIST_LAST);
-
- free(newfile);
+ } else {
+ for (cnt = 0; cnt < n; cnt++) {
+ if (strcmp(de[cnt]->d_name, ".")
+ && strcmp(de[cnt]->d_name, "..")) {
+ char *newfile;
+
+ newfile = estrjoin("", path, "/", de[cnt]->d_name, NULL);
+
+ /* This ensures we go down one level even if not fully recursive
+ - this way "feh some_dir" expands to some_dir's contents */
+ if (opt.recursive)
+ add_file_to_filelist_recursively(newfile, FILELIST_CONTINUE);
+ else
+ add_file_to_filelist_recursively(newfile, FILELIST_LAST);
+
+ free(newfile);
+ }
+ free(de[cnt]);
}
- free(de[cnt]);
+ free(de);
}
- free(de);
closedir(dir);
} else if (S_ISREG(st.st_mode)) {
D(("Adding regular file %s to filelist\n", path));