summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordg <dg@FreeBSD.org>1997-08-15 05:21:16 +0000
committerdg <dg@FreeBSD.org>1997-08-15 05:21:16 +0000
commita6696ae844e80caea556890ed6f90871322f0d96 (patch)
tree3ac95adab24f34b7c34b6fd5f240a1f7f7fc470e /lib
parenta629e89a7a525f5cd0673bdc7087d6d9626ba748 (diff)
downloadFreeBSD-src-a6696ae844e80caea556890ed6f90871322f0d96.zip
FreeBSD-src-a6696ae844e80caea556890ed6f90871322f0d96.tar.gz
Fixed file descriptor leak that occurs after certain types of failures.
PR: 3516 Submitted by: Matthew Flatt <mflatt@cs.rice.edu>
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/getcwd.c7
1 files changed, 5 insertions, 2 deletions
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);
}
OpenPOWER on IntegriCloud