From 8730a7ccff4c5ed419045f57690fb82fd2c9fc85 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 27 Nov 1996 22:00:46 +0000 Subject: Fix file descriptor leak on error. Noticed by bitblt. --- lib/libc/gen/getcwd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 1ef4183f97d..19f811a2fc3 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getcwd.c,v 1.2 1996/08/19 08:23:15 tholo Exp $"; +static char rcsid[] = "$OpenBSD: getcwd.c,v 1.3 1996/11/27 22:00:45 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -55,7 +55,7 @@ getcwd(pt, size) size_t size; { register struct dirent *dp; - register DIR *dir; + register DIR *dir = NULL; register dev_t dev; register ino_t ino; register int first; @@ -226,5 +226,7 @@ err: if (ptsize) free(pt); free(up); + if (dir) + (void)closedir(dir); return (NULL); } -- cgit v1.2.3