Fix previous not to lead fd on failure.

This commit is contained in:
Nicholas Marriott 2013-10-05 11:40:47 +01:00
parent 3493b7dac7
commit 710eeb2a33
1 changed files with 9 additions and 7 deletions

16
tmux.c
View File

@ -130,23 +130,25 @@ areshell(const char *shell)
const char *
get_full_path(const char *wd, const char *path)
{
int fd;
static char newpath[MAXPATHLEN];
int fd;
static char newpath[MAXPATHLEN];
const char *retval;
fd = open(".", O_RDONLY);
if (fd == -1)
return (NULL);
if (chdir(wd) != 0)
return (NULL);
if (realpath(path, newpath) != 0)
return (NULL);
retval = NULL;
if (chdir(wd) == 0) {
if (realpath(path, newpath) == 0)
retval = newpath;
}
if (fchdir(fd) != 0)
chdir("/");
close(fd);
return (newpath);
return (retval);
}
void