1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

(sem_open): Only call __libc_close if file descriptor is valid.

This commit is contained in:
Ulrich Drepper
2003-02-25 08:47:25 +00:00
parent 3857ca787c
commit 73983ece25

View File

@ -230,9 +230,6 @@ sem_open (const char *name, int oflag, ...)
/* Create the file. Don't overwrite an existing file. */ /* Create the file. Don't overwrite an existing file. */
if (link (tmpfname, finalname) != 0) if (link (tmpfname, finalname) != 0)
{ {
/* Remove the file. */
unlink (tmpfname);
/* Undo the mapping. */ /* Undo the mapping. */
(void) munmap (result, sizeof (sem_t)); (void) munmap (result, sizeof (sem_t));
@ -242,9 +239,17 @@ sem_open (const char *name, int oflag, ...)
/* This failed. If O_EXCL is not set and the problem was /* This failed. If O_EXCL is not set and the problem was
that the file exists, try again. */ that the file exists, try again. */
if ((oflag & O_EXCL) == 0 && errno == EEXIST) if ((oflag & O_EXCL) == 0 && errno == EEXIST)
{
/* Remove the file. */
(void) unlink (tmpfname);
/* Close the file. */
(void) __libc_close (fd);
goto try_again; goto try_again;
} }
} }
}
/* Now remove the temporary name. This should never fail. If /* Now remove the temporary name. This should never fail. If
it fails we leak a file name. Better fix the kernel. */ it fails we leak a file name. Better fix the kernel. */
@ -256,7 +261,8 @@ sem_open (const char *name, int oflag, ...)
result = SEM_FAILED; result = SEM_FAILED;
/* We don't need the file descriptor anymore. */ /* We don't need the file descriptor anymore. */
__libc_close (fd); if (fd != -1)
(void) __libc_close (fd);
return result; return result;
} }