about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-05-25 22:50:11 +0000
committerUlrich Drepper <drepper@redhat.com>1999-05-25 22:50:11 +0000
commit475e390e80a950a8746dc0b88341742dc99014e4 (patch)
tree25d17609ee32f6f37e9d204d00af0dbcb38121bf /sysdeps
parent859a09cff1dc7d626a13e242d035107e7b6d13f8 (diff)
downloadglibc-475e390e80a950a8746dc0b88341742dc99014e4.tar.gz
glibc-475e390e80a950a8746dc0b88341742dc99014e4.tar.xz
glibc-475e390e80a950a8746dc0b88341742dc99014e4.zip
Update.
1999-05-25  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/posix/getcwd.c (__getcwd): Fix potential memory leaks.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/getcwd.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index df48804f7a..fe094b5a35 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -211,8 +211,9 @@ __getcwd (buf, size)
     = "../../../../../../../../../../../../../../../../../../../../../../../\
 ../../../../../../../../../../../../../../../../../../../../../../../../../../\
 ../../../../../../../../../../../../../../../../../../../../../../../../../..";
-  const char *dotp, *dotlist;
-  size_t dotsize;
+  const char *dotp = &dots[sizeof (dots)];
+  const char *dotlist = dots;
+  size_t dotsize = sizeof (dots) - 1;
   dev_t rootdev, thisdev;
   ino_t rootino, thisino;
   char *path;
@@ -244,18 +245,15 @@ __getcwd (buf, size)
   *--pathp = '\0';
 
   if (__lstat (".", &st) < 0)
-    return NULL;
+    goto lose2;
   thisdev = st.st_dev;
   thisino = st.st_ino;
 
   if (__lstat ("/", &st) < 0)
-    return NULL;
+    goto lose2;
   rootdev = st.st_dev;
   rootino = st.st_ino;
 
-  dotsize = sizeof (dots) - 1;
-  dotp = &dots[sizeof (dots)];
-  dotlist = dots;
   while (!(thisdev == rootdev && thisino == rootino))
     {
       register DIR *dirstream;
@@ -273,7 +271,7 @@ __getcwd (buf, size)
 	    {
 	      new = malloc (dotsize * 2 + 1);
 	      if (new == NULL)
-		return NULL;
+		goto lose;
 #ifdef HAVE_MEMPCPY
 	      dotp = mempcpy (new, dots, dotsize);
 #else
@@ -375,7 +373,6 @@ __getcwd (buf, size)
 		  if (tmp == NULL)
 		    {
 		      (void) __closedir (dirstream);
-		      free (path);
 		      __set_errno (ENOMEM);/* closedir might have changed it.*/
 		      goto lose;
 		    }
@@ -412,6 +409,9 @@ __getcwd (buf, size)
  lose:
   if (dotlist != dots)
     free ((__ptr_t) dotlist);
+ lose2:
+  if (buf == NULL)
+    free (path);
   return NULL;
 }