summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/tmux.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-10-05 10:40:49 +0000
committernicm <nicm@openbsd.org>2013-10-05 10:40:49 +0000
commit41c58c32ce3e97ecd9c3e2357e117e4999fc7dde (patch)
tree11ab2a23ba320d94ca865de57a23250e7f391e39 /usr.bin/tmux/tmux.c
parentUse open(".")/fchdir() to save and restore current directory rather than (diff)
downloadwireguard-openbsd-41c58c32ce3e97ecd9c3e2357e117e4999fc7dde.tar.xz
wireguard-openbsd-41c58c32ce3e97ecd9c3e2357e117e4999fc7dde.zip
Fix previous not to leak fd on failure, whoops.
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r--usr.bin/tmux/tmux.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index efa5ed3e365..597d2ea0799 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.121 2013/10/05 08:12:39 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.122 2013/10/05 10:40:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -127,23 +127,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