diff options
author | Michael Vorburger <mike@vorburger.ch> | 2013-12-29 22:34:11 +0100 |
---|---|---|
committer | Michael Vorburger <mike@vorburger.ch> | 2013-12-29 22:34:11 +0100 |
commit | 5f210b5b2b0b150acf8f4b5890c9811cd65e2aa9 (patch) | |
tree | d1493a9a5802119dd97696ea4c7f6838edcdbd0f | |
parent | e50276645629cf81978853a326b5fc4a30fa0105 (diff) |
Fix for segfault due to errononeous free() in case of scandir error ^Cailed to scan directory'
-rw-r--r-- | src/filelist.c | 38 |
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)); |