From b50b4bd1373e9c04c2d7b801ee3d7cd82c347e4a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 1 Jun 2005 18:56:00 +0000 Subject: Save errno from clobbering by clsoedir() in the err case. From Andrey Matveev; OK deraadt@ --- lib/libc/gen/getcwd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index a58988032be..5b9d5c6a609 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getcwd.c,v 1.12 2005/03/25 15:38:47 otto Exp $"; +static char rcsid[] = "$OpenBSD: getcwd.c,v 1.13 2005/06/01 18:55:59 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -221,10 +221,15 @@ notfound: errno = save_errno ? save_errno : ENOENT; /* FALLTHROUGH */ err: + save_errno = errno; + if (ptsize) free(pt); free(up); if (dir) (void)closedir(dir); + + errno = save_errno; + return (NULL); } -- cgit v1.2.3