- winio.c:browser_init(), striponedir(), do_browse_from() - Various memory leak fixes (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1453 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2003-02-12 23:49:56 +00:00
parent d127c71ab3
commit e9b5c6fe90
2 changed files with 11 additions and 4 deletions

View File

@ -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.

13
files.c
View File

@ -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