diff --git a/ChangeLog b/ChangeLog index bd34509d17763a8e472b60552b7fec3590dfe3b4..70634397f5d749447b748c3cc442d2287ef76355 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,8 @@ CVS code - Only goto_abort() if we *didnt* abort the command, making the function seem horribly misnamed ;-) (David Benbennick). - winio.c: + browser_init(), striponedir(), do_browse_from() + - Various memory leak fixes (David Benbennick). do_yesno(), do_help() - Add defined(NCURSES_MOUSE_VERSION) to macro so systems that don't understand MEVENT will compile. diff --git a/files.c b/files.c index db4e5faa99830a1ff2fa2ce8e61e201a2985ba7c..40c25a7a45983dc720cc7e75cbb529056374bdda 100644 --- a/files.c +++ b/files.c @@ -2396,13 +2396,15 @@ void striponedir(char *foo) { char *tmp; + assert(foo != NULL); /* Don't strip the root dir */ - if (!strcmp(foo, "/")) + if (*foo == '\0' || strcmp(foo, "/") == 0) return; - tmp = foo + strlen(foo); + tmp = foo + strlen(foo) - 1; + assert(tmp >= foo); if (*tmp == '/') - tmp--; + *tmp = '\0'; while (*tmp != '/' && tmp != foo) tmp--; @@ -2464,6 +2466,7 @@ char **browser_init(const char *path, int *longest, int *numents) sprintf(filelist[i], "%s/%s", path, next->d_name); i++; } + closedir(dir); if (*longest > COLS - 1) *longest = COLS - 1; @@ -2841,8 +2844,10 @@ char *do_browse_from(const char *inpath) if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { striponedir(path); - if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) + if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { + free(path); path = getcwd(NULL, PATH_MAX + 1); + } } #ifndef DISABLE_OPERATINGDIR