Skip to content
Snippets Groups Projects
Commit c432928b authored by Yorhel's avatar Yorhel
Browse files

Fixed subdirectory name after refresh and a tiny memory leak

parent 2738177f
No related branches found
No related tags found
No related merge requests found
...@@ -297,27 +297,32 @@ int calc_key(int ch) { ...@@ -297,27 +297,32 @@ int calc_key(int ch) {
void calc_process() { void calc_process() {
char *tmp; char *path, *name;
struct stat fs; struct stat fs;
struct dir *t; struct dir *t;
/* check root directory */ /* check root directory */
if((tmp = path_real(curpath)) == NULL) { if((path = path_real(curpath)) == NULL) {
failed = 1; failed = 1;
strcpy(errmsg, "Directory not found"); strcpy(errmsg, "Directory not found");
goto calc_fail; goto calc_fail;
} }
/* split into path and last component */
name = strrchr(path, '/');
*(name++) = 0;
/* we need to chdir so we can provide relative paths for lstat() and opendir(), /* we need to chdir so we can provide relative paths for lstat() and opendir(),
* this to prevent creating path names longer than PATH_MAX */ * this to prevent creating path names longer than PATH_MAX */
if(path_chdir(tmp) < 0 || chdir("..") < 0) { if(path_chdir(path) < 0) {
failed = 1; failed = 1;
strcpy(errmsg, "Couldn't chdir into directory"); strcpy(errmsg, "Couldn't chdir into directory");
free(path);
goto calc_fail; goto calc_fail;
} }
/* would be strange for this to fail, but oh well... */ /* would be strange for this to fail, but oh well... */
if(lstat(tmp, &fs) != 0 || !S_ISDIR(fs.st_mode)) { if(lstat(name, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
failed = 1; failed = 1;
strcpy(errmsg, "Couldn't stat directory"); strcpy(errmsg, "Couldn't stat directory");
free(path);
goto calc_fail; goto calc_fail;
} }
...@@ -326,9 +331,18 @@ void calc_process() { ...@@ -326,9 +331,18 @@ void calc_process() {
t->size = fs.st_blocks * S_BLKSIZE; t->size = fs.st_blocks * S_BLKSIZE;
t->asize = fs.st_size; t->asize = fs.st_size;
t->flags |= FF_DIR; t->flags |= FF_DIR;
t->name = tmp; if(orig) {
t->name = malloc(strlen(orig->name)+1);
strcpy(t->name, orig->name);
} else {
t->name = malloc(strlen(path)+strlen(name)+1);
strcpy(t->name, path);
strcat(t->name, "/");
strcat(t->name, name);
}
root = t; root = t;
curdev = fs.st_dev; curdev = fs.st_dev;
free(path);
/* start calculating */ /* start calculating */
if(!calc_dir(root) && !failed) { if(!calc_dir(root) && !failed) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment