diff options
Diffstat (limited to 'lib/utils/dirsize.cpp')
| -rw-r--r-- | lib/utils/dirsize.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/utils/dirsize.cpp b/lib/utils/dirsize.cpp index 739b6b73..79f429e3 100644 --- a/lib/utils/dirsize.cpp +++ b/lib/utils/dirsize.cpp @@ -33,17 +33,21 @@ double get_dirsize(const char *pPath) { if (dot_or_dotdot(ep->d_name)) continue; - string dname = concat_path_file(pPath, ep->d_name); - if (lstat(dname.c_str(), &statbuf) != 0) + char *dname = concat_path_file(pPath, ep->d_name); + if (lstat(dname, &statbuf) != 0) + { + free(dname); continue; + } if (S_ISDIR(statbuf.st_mode)) { - size += get_dirsize(dname.c_str()); + size += get_dirsize(dname); } else if (S_ISREG(statbuf.st_mode)) { size += statbuf.st_size; } + free(dname); } closedir(dp); return size; @@ -66,12 +70,15 @@ double get_dirsize_find_largest_dir( { if (dot_or_dotdot(ep->d_name)) continue; - string dname = concat_path_file(pPath, ep->d_name); - if (lstat(dname.c_str(), &statbuf) != 0) + char *dname = concat_path_file(pPath, ep->d_name); + if (lstat(dname, &statbuf) != 0) + { + free(dname); continue; + } if (S_ISDIR(statbuf.st_mode)) { - double sz = get_dirsize(dname.c_str()); + double sz = get_dirsize(dname); size += sz; if (worst_dir && (!excluded || strcmp(excluded, ep->d_name) != 0)) @@ -94,6 +101,7 @@ double get_dirsize_find_largest_dir( { size += statbuf.st_size; } + free(dname); } closedir(dp); return size; |
