From a6696ae844e80caea556890ed6f90871322f0d96 Mon Sep 17 00:00:00 2001 From: dg Date: Fri, 15 Aug 1997 05:21:16 +0000 Subject: Fixed file descriptor leak that occurs after certain types of failures. PR: 3516 Submitted by: Matthew Flatt --- lib/libc/gen/getcwd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 42ca336..1593311 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -56,7 +56,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; @@ -213,7 +213,8 @@ getcwd(pt, size) *--bpt = '/'; bpt -= dp->d_namlen; bcopy(dp->d_name, bpt, dp->d_namlen); - (void)closedir(dir); + (void) closedir(dir); + dir = NULL; /* Truncate any file name. */ *bup = '\0'; @@ -231,6 +232,8 @@ notfound: err: if (ptsize) free(pt); + if (dir) + (void) closedir(dir); free(up); return (NULL); } -- cgit v1.1