aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-02-25 08:47:25 +0000
committerUlrich Drepper <drepper@redhat.com>2003-02-25 08:47:25 +0000
commit73983ece255e15160614caef84f6034f44c314ba (patch)
treedb57fbc24bf2bdbcd19260290991bbdbd709bbfc /nptl
parent3857ca787c88f420b7ead5b52fd6495ae65083e4 (diff)
downloadglibc-73983ece255e15160614caef84f6034f44c314ba.zip
glibc-73983ece255e15160614caef84f6034f44c314ba.tar.gz
glibc-73983ece255e15160614caef84f6034f44c314ba.tar.bz2
(sem_open): Only call __libc_close if file descriptor is valid.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/sem_open.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/nptl/sem_open.c b/nptl/sem_open.c
index 5def4ff..111b5f5 100644
--- a/nptl/sem_open.c
+++ b/nptl/sem_open.c
@@ -230,9 +230,6 @@ sem_open (const char *name, int oflag, ...)
/* Create the file. Don't overwrite an existing file. */
if (link (tmpfname, finalname) != 0)
{
- /* Remove the file. */
- unlink (tmpfname);
-
/* Undo the mapping. */
(void) munmap (result, sizeof (sem_t));
@@ -242,7 +239,15 @@ sem_open (const char *name, int oflag, ...)
/* This failed. If O_EXCL is not set and the problem was
that the file exists, try again. */
if ((oflag & O_EXCL) == 0 && errno == EEXIST)
- goto try_again;
+ {
+ /* Remove the file. */
+ (void) unlink (tmpfname);
+
+ /* Close the file. */
+ (void) __libc_close (fd);
+
+ goto try_again;
+ }
}
}
@@ -256,7 +261,8 @@ sem_open (const char *name, int oflag, ...)
result = SEM_FAILED;
/* We don't need the file descriptor anymore. */
- __libc_close (fd);
+ if (fd != -1)
+ (void) __libc_close (fd);
return result;
}